将数据(正文)附加到 VueJS 中的 $http.delete 事件

Posted

技术标签:

【中文标题】将数据(正文)附加到 VueJS 中的 $http.delete 事件【英文标题】:Attaching data (body) to $http.delete event in VueJS 【发布时间】:2017-02-16 10:26:37 【问题描述】:

我的 Vue.JS 组件中有以下方法:

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

在 vue-resource 0.8.0 中一切正常。升级到 1.0.3 后就没有了。我在发行说明中发现他们从 GET 请求中删除了body,这很有意义,但为什么 DELETE 请求停止工作? 如果他们禁止在 DELETE 请求中明确指定 body,我该如何添加它?

【问题讨论】:

【参考方案1】:

找到了解决办法。只需在请求中添加body:data

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

【讨论】:

以上是关于将数据(正文)附加到 VueJS 中的 $http.delete 事件的主要内容,如果未能解决你的问题,请参考以下文章