【问题标题】:typeError _ref is undefinedtypeError _ref 未定义
【发布时间】:2018-10-12 00:39:49
【问题描述】:

我只对 javascript 的基本知识做出反应,我正在我的服务器中进行处理 mysql 的查询并且连接很好,但返回是我遇到问题的地方,它假设返回一个带有查询的 JSON但我发现错误 typeError _ref is undefined here is the function where I connect to my API

callDB(){
    fetch('http://localhost:4000/lista')
    .then((response)=>{
        response.json()
    })
    .then(({data})=>{
        console.log(data);
    })
    .catch((err)=>{console.log(err);});
}

在数据部分是它没有任何想法的地方?先谢谢

【问题讨论】:

    标签: javascript mysql node.js reactjs


    【解决方案1】:

    您需要在 Promise 处理程序中返回 response.json()

    callDB(){
        fetch('http://localhost:4000/lista')
        .then((response)=>{
            return response.json()
        })
        .then(({data})=>{
            console.log(data);
        })
        .catch((err)=>{console.log(err);});
    }
    

    【讨论】:

      猜你喜欢
      • 2022-07-20
      • 2022-12-03
      • 2023-01-28
      • 2020-10-05
      • 2017-06-22
      • 2014-08-14
      • 2014-06-21
      • 2014-08-06
      • 2022-10-13
      相关资源
      最近更新 更多