VUEJS如何post到其他网站api?
VUEJS How to post to other website api?
我想post到我的api网站
The index.js
proxyTable: {
'/api': {
target: 'http://example.com',
changeOrigin: true,
pathRewrite: { '^/api': '' }
}
},
Login.vue script
submit() {
this.$http.post('/api/user/login/',{
'username':this.username,
'password':this.password
}).then(function(data){}
}
但是查看Developer Tools,报错是
GET http://localhost:8080/api/user/login 500(内部服务器错误)
那么为什么这个动作不是 POST http://example.com/api/user/login ?
查看文档。选项中未定义 HTTP 方法:
this.$http.post('/someUrl').then(response => {
// get body data
this.someData = response.body;
}, response => {
// error callback
});
要为您的所有请求设置基础 URL,您必须这样做:
Vue.http.options.root = 'http://example.com';
我建议你使用 axios 而不是 thought
我想post到我的api网站
The index.js
proxyTable: {
'/api': {
target: 'http://example.com',
changeOrigin: true,
pathRewrite: { '^/api': '' }
}
},
Login.vue script
submit() {
this.$http.post('/api/user/login/',{
'username':this.username,
'password':this.password
}).then(function(data){}
}
但是查看Developer Tools,报错是
GET http://localhost:8080/api/user/login 500(内部服务器错误)
那么为什么这个动作不是 POST http://example.com/api/user/login ?
查看文档。选项中未定义 HTTP 方法:
this.$http.post('/someUrl').then(response => {
// get body data
this.someData = response.body;
}, response => {
// error callback
});
要为您的所有请求设置基础 URL,您必须这样做:
Vue.http.options.root = 'http://example.com';
我建议你使用 axios 而不是 thought