繁体   English   中英

Vue JS使用Vue资源进行服务器调用

[英]Vue js making server call using vue-resource

我试图找出如何使用vue-resource进行以下服务器调用。 我不太确定如何使用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
})

})

您应该能够做到这一点:

Vue.http.post('http://dev-api.languagelink.com/api/auth/login', {
  email: 'foo@bar.com',
  password: 'foobar',
}).then(res => {
  // Handle success response
})

vue-resource将自动设置Content-Type标头并将有效负载字符串化为JSON。

尝试这样的事情:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM