我编写了完美运行的 put 请求,我想将它与 axios 连接起来,使其通过 onClick
方法在前端运行。
router.put("/:name", (req, res, next) => {
Papp.findOneAndUpdate({ _pappName: req.params.pappName }, req.body, {
new: true
}).then(function(state) {
res.send(state);
});
});
为了更清楚地说明:按钮通过 Prop 从数据库获取其状态。用户可以单击按钮并更改其状态,但现在只能在前端,我想更改它,以便用户能够根据请求更改数据库中的记录。
最佳答案
请遵循以下语法:
axios.put(url[, data[, config]])
例如程序:
axios.put('http://127.0.0.1/myapp/public/api/bid/'+this.itemID,
{
NewBidMade:this.NewBidMade
})
.then((response) => {
console.log(response.data);
})
.catch(function(error){
console.log(error);
});
关于javascript - 如何将 put 请求与 axios 连接以使其在前端工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60074345/