this.on react-native 上的事件发射器不是函数
this.on event Emitter on react-native is not a function
我正在尝试发出和收听一个事件。 emit 正在工作,但是当我尝试收听应用程序中断时。有人可以帮助我吗?
这是代码:
export class EmitEvents extends EventEmitter {
constructor () {
super()
this.valid_devices_list = {}
}
_discover() {
this.emit('found');
this.on('found', function () {
console.log('Got it!')
})
}
}
当我执行它时this.on给我一个错误:
this.on is not a function
对此有任何帮助吗?
class EventEmitter 在 https://github.com/facebook/react-native/blob/master/Libraries/EventEmitter/EventEmitter.js 上没有方法。
您必须改用 addListener。
我正在尝试发出和收听一个事件。 emit 正在工作,但是当我尝试收听应用程序中断时。有人可以帮助我吗?
这是代码:
export class EmitEvents extends EventEmitter {
constructor () {
super()
this.valid_devices_list = {}
}
_discover() {
this.emit('found');
this.on('found', function () {
console.log('Got it!')
})
}
}
当我执行它时this.on给我一个错误:
this.on is not a function
对此有任何帮助吗?
class EventEmitter 在 https://github.com/facebook/react-native/blob/master/Libraries/EventEmitter/EventEmitter.js 上没有方法。
您必须改用 addListener。