【发布时间】:2019-01-21 19:34:43
【问题描述】:
我正在构建一个带有 react 的前端,其中一个组件需要接受补丁请求以增加或减少投票。
任何人都可以找出我可能会为此代码获得 400 分的原因吗?
handleIncrementVote = () => {
const { commentid, articleid } = this.state;
const vote = {
inc_votes: this.state.votes
}
axios.patch(`https://lloyd-
news.herokuapp.com/api/articles/${articleid}/comments/${commentid}`,
{
vote })
.then(res => {
console.log(res);
this.setState((prevState) => ({
inc_votes: prevState.votes + 1
}), () => {
console.log(this.state.votes)
})
}).catch(err => console.log(err))
当我使用邮递员发送请求时,它工作正常。有任何想法吗?我的语法看起来还行吗?
【问题讨论】:
-
您到底要向邮递员发送什么请求?您的开发工具中的网络面板显示什么?
-
您是否检查了开发工具中的网络选项卡以确保您的请求与您在 Postman 中发出的请求相匹配?
-
好的,所以我在变成 400 之前得到 204 无内容
-
这很可能是您看到的返回 204 的选项请求。您可以发布
patch请求的正文吗? -
在邮递员中,正文是 { "inc_votes": 5 } 正在工作
标签: javascript reactjs httprequest axios