简体   繁体   English

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

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

I'm building a front end with react and one of the components needs to take accept a patch request to increment or decrement the vote. 我正在构建一个带有react的前端,并且其中一个组件需要接受接受补丁请求以增加或减少投票。

Can anybody spot a reason why I might be getting a 400 for this code. 任何人都可以找到为什么我可能为此代码得到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))

When I send the request with postman it works fine. 当我与邮递员发送请求时,它可以正常工作。 Any ideas? 有任何想法吗? Does my syntax look ok? 我的语法看起来还好吗?

Solved. 解决了。 My bad! 我的错! I was passing in this.props rather than this.state in my object. 我在对象中传递this.props而不是this.state。 Thanks for everyones suggestions! 感谢大家的建议!

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

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