当前位置: 首页> 教育> 培训 > 【小程序开发】TypeError: _this4.getOpenerEventChannel(...).emit is not a function 问题解决

【小程序开发】TypeError: _this4.getOpenerEventChannel(...).emit is not a function 问题解决

时间:2025/7/12 2:49:58来源:https://blog.csdn.net/qq_27752085/article/details/140556375 浏览次数:0次

使用uni-app+vue2开发微信小程序时遇到一个界面之前传参的问题。想实现的逻辑是界面返回并通知前一个界面刷新。代码如下:

GroupManager.getInstance().addGroupRemote(this.createGroupModel(), () => {uni.hideLoading()uni.showToast({icon: "success",title: "保存成功"})this.getOpenerEventChannel().emit("refreshGroup")uni.navigateBack()
}, e => {uni.hideLoading()uni.showToast({icon: "error",title: "保存失败"})
})

结果运行的时候报错:TypeError: _this4.getOpenerEventChannel(...).emit is not a function

网上查也没发现什么线索,后来想了很久才意识到我要返回的界面并不是跳转过来的上一个界面。整个跳转逻辑是:界面A跳转到界面B,界面B重定向到界面C,然后界面C返回界面A。

uni.redirectTo({url: `/pages-group/pages/group-detail/index?isEdit=false&groupType=${item.groupType}&floorId=${this.floorId}&roomId=${this.roomId}`,
})

中间的界面B在跳转界面C的时候以及从栈中推出,而这个getOpenerEventChannel我猜是会从上一个直接跳转过来的界面(界面B)中找事件通道,自然是找不到的。

最后把redirectTo改成了navigateTo,C界面先返回到B界面,B界面再向A界面发射刷新事件。问题就解决了。

关键字:【小程序开发】TypeError: _this4.getOpenerEventChannel(...).emit is not a function 问题解决

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: