taro icon indicating copy to clipboard operation
taro copied to clipboard

[h5]不能在子组件内调用Page继承类的函数($component不存在)

Open YuanQuan opened this issue 7 years ago • 2 comments

问题描述 [问题描述:站在其它人的角度尽可能清晰地、简洁地把问题描述清楚]

复现步骤 myPage.tsx

export default class coupon extends XComponent<IProps, IState> {
...
  <MyComponent></MyComponent>
...
}

Page继承类XComponent.js

export default class XComponent extends Component {
...
setPage = node => {
    this.__page_node__ = node;
  };
...
}

自定义组件MyComponent.js

export default class MyComponent extends PureComponent<IProps, IState> {
...
  componentWillMount() {
        let currentPages = Taro.getCurrentPages();
        let currentPage: any = currentPages[currentPages.length - 1];
        currentPage.$component.setPage(this);//这里会报错
    }
...

期望行为 可以想微信环境一样获得$component对象

报错信息

currentPage当中不存在$component对象

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。

  • 操作系统: [Mac]
  • Taro 版本 [1.3.2]
  • Node.js 版本 [v9.0.0]
  • 报错平台 [h5]

YuanQuan avatar Jul 02 '19 09:07 YuanQuan

欢迎提交 Issue~

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

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

Good luck and happy coding~

taro-bot avatar Jul 02 '19 09:07 taro-bot

这个有人看看么 PR都有

YuanQuan avatar Jul 05 '19 07:07 YuanQuan