📌  相关文章
📜  在反应中从 api 获取数据 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:01:26.797000             🧑  作者: Mango

代码示例3
useEffect(() => {
    const url = "https://api.adviceslip.com/advice";

    const fetchData = async () => {
      try {
        const response = await fetch(url);
        const json = await response.json();
        console.log(json);
      } catch (error) {
        console.log("error", error);
      }
    };

    fetchData();
}, []);