Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Attaching data (body) to $http.delete event in VueJS

I have the following method in my Vue.JS component:

removeItems (itemsArray) {
    this.$http.delete(this.apiUrl, {items : itemsArray})
    .then((response) => {
       this.msg = response.msg;
    });
}

In vue-resource 0.8.0 everything worked fine. After upgrading to 1.0.3 it doesn't. I found in release notes that they deleted body from GET request, which makes sense, but why did the DELETE request stop working? If they disabled specifying body explicitly in the DELETE request, how do I add it?

like image 332
ierdna Avatar asked Oct 07 '16 12:10

ierdna


1 Answers

Found a solution. Simply add {body:data} to the request:

removeItems (itemsArray) {
  this.$http.delete(this.apiUrl, {body: {items : itemsArray}})
  .then((response) => {
    this.msg = response.msg;
  });
}
like image 60
ierdna Avatar answered Oct 20 '22 15:10

ierdna