[英]Vue js making server call using vue-resource
I'm trying to figure out how to make the below server call using vue-resource. 我试图找出如何使用vue-resource进行以下服务器调用。 I not quite sure how to set the header and send data using Vue.$http.post
我不太确定如何使用Vue。$ http.post设置标头和发送数据
jQuery.ajax({
url: "http://url/",
type: "POST",
headers: {
"Content-Type": "application/json; charset=utf-8",
},
contentType: "application/json",
data: JSON.stringify({
"email": "foo",
"password": "bar
})
}) })
You should be able to just do this: 您应该能够做到这一点:
Vue.http.post('http://dev-api.languagelink.com/api/auth/login', {
email: 'foo@bar.com',
password: 'foobar',
}).then(res => {
// Handle success response
})
vue-resource will automatically set the Content-Type
header and stringifies the payload as JSON. vue-resource将自动设置
Content-Type
标头并将有效负载字符串化为JSON。
Try something like this : 尝试这样的事情:
this.$http.post('/url', data, {
headers: {
'Content-Type': 'application/json; charset=utf-8'
}
}).then(res => {
//do the stuff
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.