我正在使用axios库来获取一些数据,出现此错误:
Possible Unhandled Promise Rejection (id: 0):
Error: Network Error
Error: Network Error
at createError (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:62131:17)
at XMLHttpRequest.handleError (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:62039:16)
at XMLHttpRequest.dispatchEvent (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:17900:39)
at XMLHttpRequest.setReadyState (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:17655:20)
at XMLHttpRequest.__didCompleteResponse (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:17482:16)
at blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:17592:47
at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:3478:37)
at MessageQueue.__callFunction (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:2384:44)
at blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:2154:17
at MessageQueue.__guardSafe (blob:http://localhost:8081/c3815ce6-c51e-4580-ad86-346e4a022da3:2346:11)
我提取的代码是:
componentWillMount(){
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => {
this.state.setState({albums: response.data});
console.log(this.state.albums);
})
.then(error => console.log(error));
}
答案 0 :(得分:0)
我尝试过,它运行正常
axios.get('https://rallycoding.herokuapp.com/api/music_albums')
.then(response => {
this.setState({albums: response.data});
//console.log(this.state.albums);
console.log(response);
})
.then(error => console.log(error));
问题出在this.state.setState({albums: response.data});