React Native 实现页面返回监听

版权声明:我写的你不能转载,但是你可以复制啊。复制记得加关注啊(迷之微笑)。 https://blog.csdn.net/quhongqiang/article/details/88890343

A页面写:

import {DeviceEventEmitter} from 'react-native'

componentDidMount() {
    // 这里的`param`可以为空,接受你B页面传过来的数据
    this.subscription = DeviceEventEmitter.addListener("EventType", (param)=>{
        // 刷新界面等
    });
}

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

B页面:

import {DeviceEventEmitter} from 'react-native'

onPress={() => {
    this.props.navigation.navigate('A');
    // 这里的param可以写可以不写自己需要带参数就可以写
    DeviceEventEmitter.emit("EventType", param);
}}>

官网链接:DeviceEventEmitter官网链接

猜你喜欢

转载自blog.csdn.net/quhongqiang/article/details/88890343