从node_modules发送事件到vue



如何接收由node_module发出的事件?想要在一个vue文件中接收它

这是来自js node_module:

const EventEmitter = require('events')
class Find extends EventEmitter {
// some codes here
}
class FindInPage extends Find {
constructor (webContents, options = {}) {
super(webContents)
}
initialize () {
this.on('onValueInput', (value) => {
console.log('onValueInput received, value = ' + value)
})
}
// emit event triggered somewhere after
this.emit('onValueInput', this[findInput].value)
}

在我的vue文件中,我从js node_module实例化类,我想接收事件:

this.findInPage = new FindInPage(this.$q.electron.remote.getCurrentWebContents(), configToApply)
this.findInPage.on('onValueInput', (value) => {
console.log('onValueInput received from module, value = ' + value)
})

但是我没有收到事件onValueInput。它只在js模块中工作得很好。请帮助!

现在可以工作了。很显然,这只是一个打错电话的例子。谢谢。

最新更新