繁体   English   中英

使用axios进行补丁请求时获得400状态

[英]getting a 400 status when doing a patch request with axios

我正在构建一个带有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))

当我与邮递员发送请求时,它可以正常工作。 有任何想法吗? 我的语法看起来还好吗?

解决了。 我的错! 我在对象中传递this.props而不是this.state。 感谢大家的建议!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM