【问题标题】:react js send object to node js反应js将对象发送到节点js
【发布时间】:2021-07-07 22:32:02
【问题描述】:

当 API 调用时,我将对象发送到后端(Node js)。但我使用控制台日志检查对象。我用邮递员检查过。当我检查 POSTMAN 时,我工作得很好。但是我尝试在前端(react js)中传递一个对象,它显示为未定义。

  getnotification(){
  const userdetails={
  userid:"1235",
  username:this.state.name
  }
  axios.get('http://localhost:4000/notification/',userdetails)
  .then((res)=>{ this.setState((cur) => ({ ...cur, notification: res.data.reverse() }));

  })
}

【问题讨论】:

    标签: node.js reactjs api


    【解决方案1】:

    如果你想[POST],你需要使用axios.post(url, body)

    以下是 axios 可能的方法签名。

    axios.request(config)
    
    axios.get(url[, config])
    
    axios.delete(url[, config])
    
    axios.head(url[, config])
    
    axios.options(url[, config])
    
    axios.post(url[, data[, config]])
    
    axios.put(url[, data[, config]])
    
    axios.patch(url[, data[, config]])
    

    阅读更多https://axios-http.com/docs/api_intro/

    【讨论】:

    • no.我想使用get方法。但是当一些时间发布和修补方法时,我遇到了这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-26
    • 1970-01-01
    • 2017-06-05
    • 2021-01-24
    • 2016-11-25
    • 2018-10-09
    • 2023-04-07
    相关资源
    最近更新 更多