我的代码中不断出现以下错误:
可能的未处理的承诺拒绝(id:0): TypeError:未定义不是对象
数据未加载,可以在xcode模拟器上正常运行,但不能在Android上运行。
我要去哪里错了?
import _ from 'lodash';
import React, { Component } from 'react';
import { ScrollView } from 'react-native';
import axios from 'axios';
import Detail from './Detail';
class alxList extends Component {
state = { WrhDatas: [] };
componentDidMount() {
axios.get('http://ralxwebdev01/tod/api/tod')
.then(response => {
this.setState({ WrhDatas: response.data });
console.log(response);
})
.then(error => console.log(error));
}
Apifetch() {
axios.get('http://ralxwebdev01/tod/api/tod')
.then(response => this.setState({ WrhDatas: response.data })
.catch((error) => {
console.log(error.message);
throw error;
}));
}
renderTest() {
return _.map(
_.filter(this.state.WrhDatas.Sites, { SiteCode: 'ALX' }),
x => x.Statistics.map(wrh => <Detail key={wrh.Name} wrh={wrh} />)
);
}
render() {
return (
<ScrollView>
{this.renderTest()}
</ScrollView>
);
}
}
export default alxList;