Taro: navigateTo 被打开页面调用this.getOpenerEventChannel()报错

Created on 16 Jul 2019  ·  19Comments  ·  Source: NervJS/taro

使用Taro.navigateTo跳转 被打开的界面 this. getOpenerEventChannel is not a function

enhancement

All 19 comments

欢迎提交 Issue~

如果你提交的是 bug 报告,请务必遵循 Issue 模板的规范,尽量用简洁的语言描述你的问题,最好能提供一个稳定简单的复现。🙏🙏🙏

如果你的信息提供过于模糊或不足,或者已经其他 issue 已经存在相关内容,你的 issue 有可能会被关闭。

Good luck and happy coding~

报什么错,怎么复现,你这两行字完全没看懂

报什么错,怎么复现,你这两行字完全没看懂

使用Taro.navigateTo跳转 被打开的界面 this. getOpenerEventChannel is not a function @yuche

哪个平台

哪个平台

微信小程序

@zcc19910524 请按 issue 模板提供一切必要信息。

Hello~

您的问题所提供的信息不足,我们无法定位到具体的问题。如果有空的话还请拔冗提供更具体的信息,否则这个 issue 将在 15 天后被自动关闭。

如果您在这 15 天中更新更多信息自动关闭的流程会自动取消,如有其他问题也可以发起新的 Issue。

Good luck and happy coding~

@zcc19910524 请按 issue 模板提供一切必要信息。
@Chen-jj
问题描述
Taro.navigateTo方法 传入 events参数 在被打开的界面 this对象 没有getOpenerEventChannel方法
可以参考 文档页面 https://nervjs.github.io/taro/docs/apis/interface/navigation/navigateTo.html#docsNav
https://developers.weixin.qq.com/miniprogram/dev/api/route/wx.navigateTo.html

复现步骤
A.jsx:
Taro.navigateTo({ url:../B/index?type=${type}, events: { acceptDataFromOpenedPage: (data) => { console.log(data) }, } })
B.jsx
const eventChannel = this.getOpenerEventChannel()
this对象中没有getOpenerEventChannel方法

报错信息
this.getOpenerEventChannel is not a function

系统信息

Taro CLI 1.3.8 environment info:
System:
OS: macOS 10.14.4
Shell: 3.2.57 - /bin/bash
Binaries:
Node: 8.9.1 - ~/.nvm/versions/node/v8.9.1/bin/node
npm: 6.9.0 - ~/.nvm/versions/node/v8.9.1/bin/npm
npmPackages:
@tarojs/async-await: 1.3.8 => 1.3.8
@tarojs/components: 1.3.8 => 1.3.8
@tarojs/plugin-babel: 1.3.8 => 1.3.8
@tarojs/plugin-csso: 1.3.8 => 1.3.8
@tarojs/plugin-less: 1.3.8 => 1.3.8
@tarojs/plugin-sass: 1.3.8 => 1.3.8
@tarojs/plugin-uglifyjs: 1.3.8 => 1.3.8
@tarojs/redux: 1.3.8 => 1.3.8
@tarojs/redux-h5: 1.3.8 => 1.3.8
@tarojs/router: 1.3.8 => 1.3.8
@tarojs/taro: 1.3.8 => 1.3.8
@tarojs/taro-alipay: 1.3.8 => 1.3.8
@tarojs/taro-h5: 1.3.8 => 1.3.8
@tarojs/taro-swan: 1.3.8 => 1.3.8
@tarojs/taro-tt: 1.3.8 => 1.3.8
@tarojs/taro-weapp: 1.3.8 => 1.3.8
@tarojs/webpack-runner: 1.3.8 => 1.3.8
eslint-config-taro: 1.3.8 => 1.3.8
eslint-plugin-taro: 1.3.8 => 1.3.8
nerv-devtools: ^1.4.3 => 1.4.3
nervjs: ^1.4.3 => 1.4.3

@zcc19910524 使用 this.$scope.getOpenerEventChannel,因为 this.$scope 才是原生小程序的页面或组件实例。

@zcc19910524 之后会把 this.$scope 的这些特殊方法挂 this 上。

现在在模拟器上用这个方法可以,但是在手机上测试是不好用的,第一在navigateTo的success回调中res根本没有eventChannle字段,在手机上打印的log如下
image
其二就是在被打开的页面中也没有getOpenerEventChannel方法

不知道是不是版本的原因,我用的是2.10.4,然后在this.$mp.page里面找到了getOpenerEventChannel方法,使用this.$mp.page.getOpenerEventChannel()就没问题了(真的是找了很久)

是的,wepy 同理, this.getOpenerEventChannel 改成 this.$wx.getOpenerEventChannel() 就解决啦

Taro3 没有 this.$scope 的概念了。

Taro3 没有 this.$scope 的概念了。

Taro3怎么使用getOpenerEventChannel方法?

@Murphycx94 不需要用这个,可以直接用 Taro Event

@Chen-jj https://huaoguo.github.io/taro/2020/11/11/taro3-page-event.html
Taro Event 无法很好的应对这个场景啊

@Chen-jj 发现 navigateTo 的 success 回调时机在真机和模拟器不同,真机是在 constructor、componentWillMount、componentDidMount 运行完后,success 才执行,模拟器不是。

Taro3 删除了获得小程序页面对象的方法之后,感觉好多功能都不能使用了,比如channel的使用。另外Taro3提供的eventCenter在页面挑转成功后触发事件,可能在跳转后的页面还没有注册监听事件。

Was this page helpful?
0 / 5 - 0 ratings

Related issues

LadyChatterleyLover picture LadyChatterleyLover  ·  3Comments

fxy5869571 picture fxy5869571  ·  3Comments

ruixiu picture ruixiu  ·  3Comments

wyhaya picture wyhaya  ·  3Comments

chankamlam picture chankamlam  ·  3Comments