React Native 实现页面返回监听


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);
}}>


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM