美文网首页RN
ReactNative开发之DeviceEventEmitter

ReactNative开发之DeviceEventEmitter

作者: 漂泊_sbb | 来源:发表于2017-12-02 14:58 被阅读452次

在页面A中进行注册:

 import  {
  DeviceEventEmitter
  } from 'react-native';

  //注册这个监听事件
  componentDidMount(){
       DeviceEventEmitter.addListener('xxxName’, Function);
  };

 //在组件销毁的时候要将其移除
 componentWillUnmount(){
     DeviceEventEmitter.remove();
 };

在页面B中就可以进行掉用了:

import  {
 DeviceEventEmitter
 } from 'react-native';

 //调用事件通知  param是指传递的相应参数
 DeviceEventEmitter.emit('xxxName’,param);

参考链接

博客原文

相关文章

网友评论

  • 7e8633d9b796:我写了个监听成功就跳转,但现在的问题是跳转不了,但有打印出log,这是什么原因,求大神知会
    componentDidMount(){
    //注册扫描监听
    DeviceEventEmitter.addListener('onXGPushResult',(data)=>this.pushTo(data));
    }
    pushTo(data){
    console.log("data:"+data);
    const { navigate } = this.props.navigation;
    navigate(data);
    }

本文标题:ReactNative开发之DeviceEventEmitter

本文链接:https://www.haomeiwen.com/subject/srunbxtx.html