收藏
回答

为什么wx.navigateBack 调用eventChannel会失败

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.navigateBack 微信iOS客户端 7.0.1 2.8.3

为什么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)

回答关注问题邀请回答
收藏

1 个回答

  • brave
    brave
    2022-03-01

    定义一个事件: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()
    
    2022-03-01
    有用 2
    回复
登录 后发表内容