NervJS / taro-ui

一款基于 Taro 框架开发的多端 UI 组件库
https://taro-ui.taro.zone
MIT License
4.52k stars 756 forks source link

countDown组件重置不生效问题,componentWillReceiveProps接收参数后,执行clearTimeout,并没有清掉this.timer的值,所以setTimer的时候就走不进去了 #1524

Open dipingxian opened 2 years ago

dipingxian commented 2 years ago

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch taro-ui@3.1.0-beta.3 for the project I'm working on.

Here is the diff that solved my problem:

diff --git a/node_modules/taro-ui/dist/index.esm.js b/node_modules/taro-ui/dist/index.esm.js
index 2041192..f9adac1 100644
--- a/node_modules/taro-ui/dist/index.esm.js
+++ b/node_modules/taro-ui/dist/index.esm.js
@@ -5539,6 +5539,7 @@ var AtCountdown = /** @class */ (function (_super) {
     AtCountdown.prototype.clearTimer = function () {
         if (this.timer) {
             clearTimeout(this.timer);
+            this.timer = null
         }
     };
     AtCountdown.prototype.calculateTime = function () {
diff --git a/node_modules/taro-ui/lib/components/countdown/index.js b/node_modules/taro-ui/lib/components/countdown/index.js
index 3b56756..dabddff 100644
--- a/node_modules/taro-ui/lib/components/countdown/index.js
+++ b/node_modules/taro-ui/lib/components/countdown/index.js
@@ -9,6 +9,7 @@ export default class AtCountdown extends React.Component {
         super(props);
         const { day = 0, hours = 0, minutes = 0, seconds = 0 } = this.props;
         this.seconds = toSeconds(day, hours, minutes, seconds);
+        console.log('AtCountdown======================constructor')
         const { day: _day, hours: _hours, minutes: _minutes, seconds: _seconds } = this.calculateTime();
         this.state = {
             _day,
@@ -64,6 +65,8 @@ export default class AtCountdown extends React.Component {
         }, 1000);
     }
     UNSAFE_componentWillReceiveProps(nextProps) {
+        debugger
+        console.log('AtCountdown======================constructor')
         if (JSON.stringify(this.props) === JSON.stringify(nextProps))
             return;
         const { day, hours, minutes, seconds } = nextProps;

This issue body was partially generated by patch-package.

taro-ui-bot[bot] commented 2 years ago

欢迎提交 Issue~

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

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

Good luck and happy coding~

dipingxian commented 2 years ago

image this.timer再清除的时候要置为null,否则值是不会被清除掉的

SidneyLann commented 2 years ago

这个项目已停止维护了,还提它干啥?!

dipingxian commented 2 years ago

没有吧,看着最近还有更新来着