【问题标题】:possible unhandled promise rejection (id 0) react native可能未处理的承诺拒绝(id 0)反应原生
【发布时间】:2020-05-04 17:01:27
【问题描述】:

此代码在 Expio.io 在线上正常工作,但是当我尝试使用 Visual Studio 代码时出现网络错误 “可能未处理的承诺拒绝(id 0)反应原生”

这里是代码 '''

 state={
 Data:[]
 }   
 componentDidMount(){
 axios.get("http://localhost:63007/api/values/GetCoustomer")
.then(response => {
 this.setState({Data: response.data});
 console.log(response.statusText);
 })
.then(error => console.log(error));
 }

'''

【问题讨论】:

标签: react-native axios fetch


【解决方案1】:

你错过了一个 catch 块。它应该是这样的:

axios.get("http://localhost:63007/api/values/GetCoustomer")
  .then(function (response) {
    // handle success
    this.setState({Data: response.data});
 console.log(response.statusText);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })
  .then(function () {
    // always executed
  });


【讨论】:

    猜你喜欢
    • 2018-04-19
    • 1970-01-01
    • 2017-12-20
    • 2018-03-11
    • 2018-07-14
    • 2019-10-06
    • 2020-10-09
    • 2023-01-04
    • 1970-01-01
    相关资源
    最近更新 更多