• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
smileyqp
https://github.com/smileyqp
博客园    首页    新随笔    联系   管理    订阅  订阅

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);
}}>
posted @ 2019-07-25 10:13  smileyqp  阅读(2029)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3