事件的订阅与发送:DeviceEventEmitter
注册事件监听
import {
DeviceEventEmitter,
} from
'react-native';
class XiFan extends Component {
componentDidMount(){
this.subscription = DeviceEventEmitter.addListener(
'dataChange',
this._onListenerCallback.bind(
this));
}
componentWillUnmount(){
this.subscription.remove();
}
_onListenerCallback(params){
console.log(
'params = '+ params);
};
}
在另一个组件中,需要发送通知时,调用:
DeviceEventEmitter.emit(
'dataChange',
params);
转载请注明原文地址: https://ju.6miu.com/read-1303504.html