在需要根据监听内容发生改变的文件中的componentDidMount中写下如下代码:
componentDidMount() {
this.subscription = DeviceEventEmitter.addListener('Key', (data) => {
//内容
});
在需要设置监听的地方这样写可以传参:
DeviceEventEmitter.emit('Key', '待传参数')
在需要根据监听内容发生改变的文件中的componentDidMount中写下如下代码:
componentDidMount() {
this.subscription = DeviceEventEmitter.addListener('Key', (data) => {
//内容
});
在需要设置监听的地方这样写可以传参:
DeviceEventEmitter.emit('Key', '待传参数')