Vue js使用vue-resource进行服务器调用

问题描述 投票:-1回答:2

我试图弄清楚如何使用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
})

})

javascript vue.js vuejs2 vue-resource
2个回答
1
投票

你应该能够这样做:

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

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


1
投票

尝试这样的事情:

this.$http.post('/url', data, {
   headers: {
       'Content-Type': 'application/json; charset=utf-8'
   }
}).then(res => {
//do the stuff
});
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.