自学内容网 自学内容网

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

使用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界面发射刷新事件。问题就解决了。


原文地址:https://blog.csdn.net/qq_27752085/article/details/140556375

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!