RN使用 createBottomTabNavigator 创建底部导航栏时,只会在第一次创建时调用 componentDidMount 钩子,
当跳转到另一个页面,点击返回键再次返回到此页面时不会再次调用,但我们往往需要在返回此页面后重新执行获取数据等方法函数。
解决方法
子页面:
componentDidMount() {
this._navListener = this.props.navigation.addListener('didFocus', () => {
this.getData();
});
}
componentWillUnmount() {
this._navListener.remove();
}