【问题标题】:AXIOS calls and rendering dataAXIOS 调用和渲染数据
【发布时间】:2020-11-16 09:07:41
【问题描述】:

我是 React 和 AXIOS 的新手。我正在尝试将 API 调用中的数据(分配给用户的问题)呈现到我的页面上。在 (.then) 语句中运行函数是否有任何限制?

这是我的 AXIOS 请求

    axios
      .get(
        "/api/v1/assigned-questions?userId=61d7d1be-4ada-4c1a-81c0-c6b82f45132e"
     )
     .then((res) => {
        // handle success
        const assignedQuestions = res.data[0];
        // object with a collection of data
        console.log(assignedQuestions);
        this.setState({ currentUser: assignedQuestions });
     })
     .catch((error) => {
        // handle error
        console.log(error);
     });

【问题讨论】:

    标签: javascript mysql reactjs axios postman


    【解决方案1】:

    在 .then 中运行函数没有任何限制。 .then 接受一个作为响应处理程序的函数,它可以在其中执行任意数量的语句。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-31
      • 2021-01-07
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 2020-04-14
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多