【问题标题】:this.on event Emitter on react-native is not a functionreact-native 上的 this.on 事件发射器不是函数
【发布时间】:2016-11-01 10:01:52
【问题描述】:

我正在尝试发出和监听一个事件。发射正在工作,但是当我尝试收听应用程序时会中断。有人可以帮我解决这个问题吗?

这是代码:

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 不是函数

有什么帮助吗?

【问题讨论】:

    标签: javascript node.js reactjs react-native dom-events


    【解决方案1】:

    EventEmitter 类在 https://github.com/facebook/react-native/blob/master/Libraries/EventEmitter/EventEmitter.js 上没有方法。

    您必须改用 addListener。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-28
      • 1970-01-01
      • 2015-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-27
      相关资源
      最近更新 更多