ReactNative DeviceEventEmitter
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:参数