使用axios的网络错误和反应原生的fetch

时间:2017-07-23 11:14:24

标签: javascript react-native axios

我想在我的应用项目中使用axios,但是会收到此错误

  

网络请求失败

我的代码是:

  fetch('https://facebook.github.io/react-native/movies.json').then(function(response) {

      alert(response.data);
  }).catch(function(response) {

      alert(response)

  });

我测试了这个,但它也不起作用

Axios公司:

   Axios.get('https://facebook.github.io/react-native/movies.json').then(function(response) {

   }).catch(function(error) {
       // alert(error)
       console.warn(error)
   });

1 个答案:

答案 0 :(得分:1)

这会对你有帮助。

state = { abc:[] };

componentWillMount() {

 axios.get('url')//lowercase a
.then(response => this.setState({abc:response.data})).catch((error) => {
     console.error(error);
 });
}
相关问题