Search code examples
vue.jsvue-resource

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?


Solution

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