简体   繁体   中英

Vue js making server call using vue-resource

I'm trying to figure out how to make the below server call using vue-resource. I not quite sure how to set the header and send data using 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.

Try something like this :

this.$http.post('/url', data, {
   headers: {
       'Content-Type': 'application/json; charset=utf-8'
   }
}).then(res => {
//do the stuff
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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