显示第一页时,将调用属于最后一页的React-Native ViewPagerAndroid函数componentDidMount

时间:2016-05-10 10:04:08

标签: android react-native

我的ViewPagerAndroid有四页(1-4)。

函数componentDidMount属于第4页,我用它从服务器加载用户信息。

我希望在看到第4页时获取信息,但现在,当我看到第1页时,会调用此函数。

1 个答案:

答案 0 :(得分:0)

请改用componentWillReceiveProps。 现在我的问题解决了。

<MePage
      key={i}
      onShowing={this.state.currentKey === this.props.items[i].key}
      navigator={this.props.navigator}
    />

componentWillReceiveProps(nextProps) {
    if (nextProps.onShowing) {
      alert('hi');
    }
}