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

weapp ios 真机子组件不调用componentDidMount #4458

Closed
nsyujian opened this issue Sep 12, 2019 · 8 comments
Closed

weapp ios 真机子组件不调用componentDidMount #4458

nsyujian opened this issue Sep 12, 2019 · 8 comments
Assignees
Labels
question Further information is requested

Comments

@nsyujian
Copy link

问题描述
页面结构如下图所示:
有俩个Tab页首页和店铺,店铺页面的组件在经过下面复现步骤的操作会触发bug,子组件componentDidMount不调用 (只有iOS真机会出现,微信小程序基础库版本2.8.2)
屏幕快照 2019-09-12 19 23 39
屏幕快照 2019-09-12 19 23 49

复现步骤

  1. 进入应用,点击店铺页面
  2. 点击清空列表,清空店铺页面子组件
  3. 切换到首页,点击调整二级页面,设置店铺页面数据重新渲染子组件
  4. 店铺页面子组件不触发componentDidMount

复现demo

系统信息

Taro v1.2 及以上版本已添加 taro info 命令,方便大家查看系统及依赖信息,运行该命令后将结果贴下面即可。
Taro CLI 1.3.14 environment info:
System:
OS: macOS 10.14.6
Shell: 5.3 - /bin/zsh
Binaries:
Node: 10.15.1 - ~/.nvm/versions/node/v10.15.1/bin/node
Yarn: 1.13.0 - /usr/local/bin/yarn
npm: 6.4.1 - ~/.nvm/versions/node/v10.15.1/bin/npm
npmPackages:
@tarojs/async-await: 1.3.14 => 1.3.14
@tarojs/components: 1.3.14 => 1.3.14
@tarojs/plugin-babel: 1.3.14 => 1.3.14
@tarojs/plugin-csso: 1.3.14 => 1.3.14
@tarojs/plugin-sass: ^1.3.18 => 1.3.18
@tarojs/plugin-uglifyjs: 1.3.14 => 1.3.14
@tarojs/redux: 1.3.14 => 1.3.14
@tarojs/redux-h5: 1.3.14 => 1.3.14
@tarojs/router: 1.3.14 => 1.3.14
@tarojs/taro: 1.3.14 => 1.3.14
@tarojs/taro-alipay: 1.3.14 => 1.3.14
@tarojs/taro-h5: 1.3.14 => 1.3.14
@tarojs/taro-swan: 1.3.14 => 1.3.14
@tarojs/taro-tt: 1.3.14 => 1.3.14
@tarojs/taro-weapp: 1.3.14 => 1.3.14
@tarojs/webpack-runner: 1.3.14 => 1.3.14
eslint-config-taro: 1.3.14 => 1.3.14
eslint-plugin-taro: 1.3.14 => 1.3.14
nerv-devtools: ^1.4.0 => 1.4.4
nervjs: ^1.4.0 => 1.4.4
stylelint-config-taro-rn: 1.3.14 => 1.3.14
stylelint-taro-rn: 1.3.14 => 1.3.14
npmGlobalPackages:
typescript: 3.5.3

  • 操作系统: [iOS]
  • 报错平台 [weapp]

补充信息
通过调试发现是小程序原生组件的ready方法没有调用

@taro-bot
Copy link

taro-bot bot commented Sep 12, 2019

欢迎提交 Issue~

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

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

Good luck and happy coding~

@taro-bot
Copy link

taro-bot bot commented Sep 16, 2019

CC @Chen-jj

@Chen-jj
Copy link
Contributor

Chen-jj commented Sep 16, 2019

@GaoYuJian 小程序的问题,这种写法会导致 ready 不触发,建议换种写法。

image

@Chen-jj Chen-jj added answered question Further information is requested labels Sep 16, 2019
@nsyujian
Copy link
Author

@Chen-jj 你好有什么替代写法吗,我们的实际场景是电商购物车,先清空购物车,再到商品详情添加商品到购物车

@taro-bot
Copy link

taro-bot bot commented Sep 16, 2019

Hello~

您的问题楼上已经有了确切的回答,如果没有更多的问题这个 issue 将在 15 天后被自动关闭。

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

Good luck and happy coding~

@Chen-jj
Copy link
Contributor

Chen-jj commented Sep 16, 2019

@GaoYuJian 把逻辑放 componentWillMount

@nsyujian
Copy link
Author

@Chen-jj
componentDidMount不调用,后续componentWillReceiveProps也不会调用,还有在componentDidMount中需要调用一下dom相关的api, 用componentWillMount不太合适

@Chen-jj
Copy link
Contributor

Chen-jj commented Sep 16, 2019

@GaoYuJian 加个变量控制一下展示时机试试

componentDidShow () {
    this.setState({
      show: true
    })
  }

  componentDidHide () {
    this.setState({
      show: false
    })
  }

  render () {
    return (
      <View className='index'>
        {this.state.show &&
          <View>
          {
            this.props.counter.testList.map((v, i) => {
              return <CheckIcon onCheckChange={checked => this.onCheckChange(checked, i)} key={v.key} defaultChecked={v.checked} />
            })
          }
          </View>
        }
      </View>
    )
  }

@taro-bot taro-bot bot removed the to be closed label Oct 1, 2019
@taro-bot taro-bot bot closed this as completed Oct 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants