【发布时间】:2018-07-30 09:13:50
【问题描述】:
可能出现未处理的 Promise Rejection (id:0) 错误:react native 中的网络错误
import React, {Component} from 'react';
import {View,Text} from 'react-native';
import axios from 'axios';
class AlbumList extends Component {
state = {albums: []};
componentWillMount() {
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response=>this.setState({albums: response.data}));
}
renderAlbums() {
return this.state.albums.map(album => <Text>{album.title}</Text>);
}
render() {
console.log(this.state);
return(
<View>
{this.renderAlbums()}
</View>
);
}
};
export default AlbumList;
// 我无法从给定的链接加载我的数据,在调试模式下也只有一个 // 创建了一个具有空值的状态,并且在 //console 中看不到其他数据,所以请帮助我获取数据
这是我遇到的错误的屏幕截图
【问题讨论】:
-
你能不能试试同样的
fetch看看
标签: android react-native android-emulator general-network-error