react-navigation createBottomTabNavigator 切换TAB刷新界面

以createBottomTabNavigator方式创建底部导航栏,只有第一次进入tab界面时会加载数据,再次点击进入无法重新加载或者刷新数据;通过在第一次渲染后注册获取焦点事件,获取焦点后重新请求刷新数据即可;在组件卸载时候进行事件移除即可

  componentDidMount() {
    
    
    this.fetchData()
    this._navListener = this.props.navigation.addListener('didFocus', () => {
    
     this.fetchData(); })
  }

  componentWillUnmount(){
    
    
    this._navListener.remove();
  }

  fetchData = () => {
    
    
    ...
  }

猜你喜欢

转载自blog.csdn.net/nongminkouhao/article/details/107819650