为什么wx.navigateBack 调用eventChannel会失败????
wx.navigateBack({
delta: 1,
success: function(res) {
res.eventChannel.emit('pagestaffchoose', data)
}
})
return
MiniProgramError
Cannot read property 'emit' of undefined
TypeError: Cannot read property 'emit' of undefined
at success (http://127.0.0.1:57434/appservice/pages/xxx/xxxxx/xxxx.js:63:30)
at Function.forEach.s.<computed> (http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:2450694)
at <api navigateBack success callback function>
at Object.success (http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:114522)
at r (http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:1191114)
at http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:1191297
at v (http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:1191301)
at http://127.0.0.1:57434/appservice/__dev__/WAService.js?t=wechat&s=1646121741371&v=2.19.1:2:1192725
at http://127.0.0.1:57434/appservice/__dev__/asdebug.js:1:48487
at C (http://127.0.0.1:57434/appservice/__dev__/asdebug.js:1:48142)
定义一个事件:someEvent
跳转前的页面:
wx.navigateTo({ url: 'test?id=1', events: { // 为指定事件添加一个监听器,获取被打开页面传送到当前页面的数据 someEvent: function(data) { console.log(data) } } })
跳转后的页面:
const eventChannel = this.getOpenerEventChannel() eventChannel.emit('someEvent', {data: 'test'}) wx.navigateBack()