簡體   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