VUEJS如何发布到其他网站api?

时间:2018-03-23 16:46:27

标签: webpack vuejs2 vue-cli

我想发布到我的api网站

  

index.js

proxyTable: { '/api': { target: 'http://example.com', changeOrigin: true, pathRewrite: { '^/api': '' } } },

  

Login.vue脚本

  submit() {
  this.$http.post('/api/user/login/',{
    'username':this.username,
    'password':this.password
    }).then(function(data){}
}

但请查看开发人员工具,错误是

获取http://localhost:8080/api/user/login 500(内部服务器错误)

那么为什么行动不是POST http://example.com/api/user/login

1 个答案:

答案 0 :(得分:1)

查看文档。 HTTP方法未在选项中定义:

this.$http.post('/someUrl').then(response => {

    // get body data
    this.someData = response.body;

  }, response => {
    // error callback
  });

要为您的所有请求设置基本网址,您必须采用以下方式:

Vue.http.options.root = 'http://example.com';

我建议您使用axios而不是

相关问题