DeviceEventEmitter(react-native中发送和接收消息得组件)

import {DeviceEventEmitter} from 'react-native';

在某个页面中监听事件消息

componentDidMount(){
    var self = this;
    this.listener =DeviceEventEmitter.addListener('xxxName',function(param){

    //  use param do something
    });
}
//页面卸载时移出事件监听
componentWillUnmount(){
      this.listener.remove();
}

在另一个页面发送事件消息

DeviceEventEmitter.emit('xxxName’,param);
//xxxName:通事件名称 param:参数

 

相关文章:

  • 2021-08-24
  • 2021-11-27
  • 2021-11-26
  • 2021-10-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-01
猜你喜欢
  • 2022-12-23
  • 2021-08-24
  • 2021-10-03
  • 2021-04-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-13
相关资源
相似解决方案