【问题标题】:can't pass data in to delete request with Vue-Resource无法使用 Vue-Resource 传递数据以删除请求
【发布时间】:2018-02-03 17:51:11
【问题描述】:

我在使用 Vue 资源传递数据以删除请求时遇到问题。服务器正在接收没有数据的空白对象。有一些代码:

带有 Vue.js 和 Vue-resourcer 的前端

deleteArticle: function(tit){
  console.log(tit);
  this.$http.delete('http://192.168.0.52:8080/article',{'title':'123'}).then((res)=>{
    this.refresh();
    console.log(res.data);
  }).catch((e)=>{console.log(e)});
}

使用 express.js API 的 node.js 路由的后端。

app.delete('/article', (req,res)=>{
 var body = _.pick(req.body,['title']);
 console.log(req.body); //printing blank object from request
 Article.findByTitleAndRemove(body.title).then((doc)=>{
  res.status(200).send(`Deleted Article with title ${doc.title}`)
 }).catch((e)=>{
  console.log(e);
  res.status(400).send(e);
 })
})

这条路线适用于邮递员。

【问题讨论】:

  • console.log(tit); 是否记录到控制台?

标签: node.js vue.js vue-resource


【解决方案1】:

试试这个:

this.$http.delete('http://192.168.0.52:8080/article', { params: { title: 123 } }).then(res => {
    this.refresh();
    console.log(res.data);
}).catch((e)=>{console.log(e)});

更新:这就是我在节点中的工作方式:

app.delete('/article', (req, res) => {
  console.log(req.query.title); 
});

【讨论】:

  • 打印仍为空的对象 :(
  • 我更新了我的答案以演示在节点中打印查询:)
猜你喜欢
  • 2016-09-30
  • 2017-11-24
  • 2017-06-01
  • 2018-01-01
  • 1970-01-01
  • 2013-09-16
  • 1970-01-01
  • 1970-01-01
  • 2018-04-11
相关资源
最近更新 更多