3 回答

TA貢獻(xiàn)1802條經(jīng)驗 獲得超10個贊
請改進(jìn)您的操作并確保您從服務(wù)器獲取 res.data。
export const showAllClasses = () => dispatch => {
dispatch(pageLoading(true));
const res = await Api.get(`classes.php`);
dispatch(onChangeClasessAll(res.data));
dispatch(pageLoading(false));
};
然后在渲染方法中控制臺 this.props 就像
render(){
console.log(this.props);
return
......
}
您將在控制臺中看到所有道具,因此您可以輕松地從那里獲取數(shù)據(jù)。

TA貢獻(xiàn)1794條經(jīng)驗 獲得超8個贊
因為您的請求是異步的。當(dāng)請求返回時,你應(yīng)該安慰它。在 react-native 0.6 中,您可以在 getDerivedStateFromProps(props, state) 方法中進(jìn)行
static getDerivedStateFromProps(props, state) {
console.log(props.classes.classesAll)
}
在 react-native 0.6 之前,你應(yīng)該在 componentWillReceiveProps() 方法中做
componentWillReceiveProps(nextProps) {
console.log(props.classes.classesAll)
}
添加回答
舉報