-1

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
})

})

shan
  • 78
  • 2
  • 9
  • 2
    How about actually [reading the documentation](https://github.com/pagekit/vue-resource/blob/develop/docs/http.md)? – herrbischoff Dec 20 '17 at 04:32

2 Answers2

1

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.

Decade Moon
  • 32,968
  • 8
  • 81
  • 101
1

Try something like this :

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