【问题标题】:how to use data from response section of post request in react js of django api call?如何在django api调用的react js中使用来自post请求的响应部分的数据?
【发布时间】:2022-01-20 21:19:17
【问题描述】:

this data i want to access

这是我的 api 调用

api
  .post("/auth/registration/", data)
  .then((res) => {
    console.log(res);
    localStorage.removeItem("access");
    localStorage.removeItem("refresh");

    alert("Registration Successfull");
  })
  .catch((error) => {
    console.log(Response.password1);
    alert(error.message);
    console.log(msg);
    localStorage.removeItem("access");
    localStorage.removeItem("refresh");
  });

我想在响应部分提醒消息来自后端,我该怎么做

【问题讨论】:

  • 你试过什么? res.email?.[0]?还是您向我们展示的错误?请为您正在尝试做的事情分享一个更完整和全面的代码示例。 stackoverflow.com/help/minimal-reproducible-example
  • 当您记录“res”时,您可以显示控制台中显示的对象。还可以尝试记录应该为您提供响应数据的“res.data”

标签: reactjs api axios


【解决方案1】:

将代码包装在 useEffect 钩子中。

【讨论】:

    猜你喜欢
    • 2021-09-23
    • 1970-01-01
    • 2019-02-02
    • 2020-01-24
    • 2022-09-17
    • 2013-03-12
    • 2014-04-21
    • 2017-10-27
    • 1970-01-01
    相关资源
    最近更新 更多