Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

类组件 componentDidShow 生命周期不执行 #9314

Closed
wanxiankai opened this issue May 12, 2021 · 2 comments
Closed

类组件 componentDidShow 生命周期不执行 #9314

wanxiankai opened this issue May 12, 2021 · 2 comments
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x

Comments

@wanxiankai
Copy link

相关平台

微信小程序

复现仓库

https://github.com/wanxiankai/taro-dome-v3
小程序基础库: 2.16.1
使用框架: React

复现步骤

下载项目之后 yarn 安装依赖
yarn dev:weapp 运行项目
可以看到组件中的didshow 生命周期没有执行

期望结果

类组件 componentDidShow 正常执行

实际结果

首次进入或者返回 ,类组件 componentDidShow 不执行

环境信息

Taro v3.2.0


  Taro CLI 3.2.0 environment info:
    System:
      OS: macOS 10.15.7
      Shell: 5.7.1 - /bin/zsh
    Binaries:
      Node: 12.21.0 - /usr/local/bin/node
      Yarn: 1.22.4 - /usr/local/bin/yarn
      npm: 6.14.11 - /usr/local/bin/npm
    npmPackages:
      @tarojs/components: 3.2.0 => 3.2.0 
      @tarojs/mini-runner: 3.2.0 => 3.2.0 
      @tarojs/react: 3.2.0 => 3.2.0 
      @tarojs/runtime: 3.2.0 => 3.2.0 
      @tarojs/taro: 3.2.0 => 3.2.0 
      @tarojs/webpack-runner: 3.2.0 => 3.2.0 
      babel-preset-taro: 3.2.0 => 3.2.0 
      eslint-config-taro: 3.2.0 => 3.2.0 
      react: ^17.0.0 => 17.0.2 
    npmGlobalPackages:
      typescript: 3.5.3
@taro-bot2 taro-bot2 bot added F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x labels May 12, 2021
@ivan-94
Copy link
Contributor

ivan-94 commented May 20, 2021

只有页面组件才能监听到 页面生命周期函数。下级组件的话:函数组件可以使用 Hooks, 类组件参照官方文档实现监听 https://taro-docs.jd.com/taro/docs/react#componentdidshow-

@Chen-jj
Copy link
Contributor

Chen-jj commented Jun 17, 2021

@ivan-94 正解

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-react Framework - React T-weapp Target - 编译到微信小程序 V-3 Version - 3.x
Projects
None yet
Development

No branches or pull requests

3 participants