js-newbee / taro-yanxuan

首个 Taro 多端统一实例 - 网易严选(小程序 + H5 + React Native) - By 趣店 FED

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

H5端,限时购的倒计时貌似有BUG

cokeyang opened this issue · comments

并没有按照预期有所显示

@cokeyang 麻烦截图看下,我这边电脑、手机看都正常

image
倒计时显示00:00:00
image
这个地方的props.data.leftTime 是未定义。

@cokeyang 麻烦给下浏览器环境,我 debug 下

image

感觉是时序的问题。

加这段之后解决了

componentWillReceiveProps(nextProps) {
this.setState({
leftTime: parseInt((nextProps.data.leftTime || 0) / 1000)
});
}

加这段之后解决了

componentWillReceiveProps(nextProps) {
this.setState({
leftTime: parseInt((nextProps.data.leftTime || 0) / 1000)
});
}

嗯嗯,我修复了哈。之前这块考虑的不够严谨,因为 leftTime 是从 props 中取的,在 constructor 中初始化。如果后续数据更新了(比如 didShow 中又拉取了一次数据进行覆盖,这个时候就有问题了,不会更新 leftTime)

思路跟你一样,在 componentWillReceiveProps 里判断 leftTime 的值是否发生了更新。

非常感谢反馈与探讨,赞一个。