feat(Circle): using setTimeout instead of setInterval (#4401)

This commit is contained in:
ascodelife 2021-08-18 10:47:44 +08:00 committed by GitHub
parent e07f9f9581
commit 41457c899b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -181,9 +181,10 @@ VantComponent({
return; return;
} }
this.clearInterval(); this.clearMockInterval();
this.currentValue = this.currentValue || 0; this.currentValue = this.currentValue || 0;
this.interval = setInterval(() => { const run = () => {
this.interval = setTimeout(() => {
if (this.currentValue !== value) { if (this.currentValue !== value) {
if (Math.abs(this.currentValue - value) < STEP) { if (Math.abs(this.currentValue - value) < STEP) {
this.currentValue = value; this.currentValue = value;
@ -193,15 +194,18 @@ VantComponent({
this.currentValue -= STEP; this.currentValue -= STEP;
} }
this.drawCircle(this.currentValue); this.drawCircle(this.currentValue);
run();
} else { } else {
this.clearInterval(); this.clearMockInterval();
} }
}, 1000 / speed); }, 1000 / speed);
};
run();
}, },
clearInterval() { clearMockInterval() {
if (this.interval) { if (this.interval) {
clearInterval(this.interval); clearTimeout(this.interval);
this.interval = null; this.interval = null;
} }
}, },
@ -216,6 +220,6 @@ VantComponent({
}, },
destroyed() { destroyed() {
this.clearInterval(); this.clearMockInterval();
}, },
}); });