mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-05-23 15:09:16 +08:00
fix(CountDown): infinite tick if call reset after finish (#5340)
This commit is contained in:
parent
07899dbe12
commit
8cb653afc7
@ -79,7 +79,7 @@ export default {
|
|||||||
:time="3000"
|
:time="3000"
|
||||||
:auto-start="false"
|
:auto-start="false"
|
||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="finished"
|
@finish="finish"
|
||||||
/>
|
/>
|
||||||
<van-grid clickable :column-num="3">
|
<van-grid clickable :column-num="3">
|
||||||
<van-grid-item text="Start" icon="play-circle-o" @click="start" />
|
<van-grid-item text="Start" icon="play-circle-o" @click="start" />
|
||||||
|
@ -89,7 +89,7 @@ export default {
|
|||||||
:time="3000"
|
:time="3000"
|
||||||
:auto-start="false"
|
:auto-start="false"
|
||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="finished"
|
@finish="finish"
|
||||||
/>
|
/>
|
||||||
<van-grid clickable>
|
<van-grid clickable>
|
||||||
<van-grid-item text="开始" icon="play-circle-o" @click="start" />
|
<van-grid-item text="开始" icon="play-circle-o" @click="start" />
|
||||||
|
@ -5,24 +5,15 @@
|
|||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block :title="$t('customFormat')">
|
<demo-block :title="$t('customFormat')">
|
||||||
<van-count-down
|
<van-count-down :time="time" :format="$t('formatWithDay')" />
|
||||||
:time="time"
|
|
||||||
:format="$t('formatWithDay')"
|
|
||||||
/>
|
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block :title="$t('millisecond')">
|
<demo-block :title="$t('millisecond')">
|
||||||
<van-count-down
|
<van-count-down millisecond :time="time" format="HH:mm:ss:SS" />
|
||||||
millisecond
|
|
||||||
:time="time"
|
|
||||||
format="HH:mm:ss:SS"
|
|
||||||
/>
|
|
||||||
</demo-block>
|
</demo-block>
|
||||||
|
|
||||||
<demo-block :title="$t('customStyle')">
|
<demo-block :title="$t('customStyle')">
|
||||||
<van-count-down
|
<van-count-down :time="time">
|
||||||
:time="time"
|
|
||||||
>
|
|
||||||
<template v-slot="currentTime">
|
<template v-slot="currentTime">
|
||||||
<span class="item">{{ currentTime.hours }}</span>
|
<span class="item">{{ currentTime.hours }}</span>
|
||||||
<span class="item">{{ currentTime.minutes }}</span>
|
<span class="item">{{ currentTime.minutes }}</span>
|
||||||
@ -40,10 +31,7 @@
|
|||||||
format="ss:SSS"
|
format="ss:SSS"
|
||||||
@finish="$toast($t('finished'))"
|
@finish="$toast($t('finished'))"
|
||||||
/>
|
/>
|
||||||
<van-grid
|
<van-grid clickable :column-num="3">
|
||||||
clickable
|
|
||||||
:column-num="3"
|
|
||||||
>
|
|
||||||
<van-grid-item
|
<van-grid-item
|
||||||
icon="play-circle-o"
|
icon="play-circle-o"
|
||||||
:text="$t('start')"
|
:text="$t('start')"
|
||||||
@ -54,11 +42,7 @@
|
|||||||
:text="$t('pause')"
|
:text="$t('pause')"
|
||||||
@click="pause"
|
@click="pause"
|
||||||
/>
|
/>
|
||||||
<van-grid-item
|
<van-grid-item icon="replay" :text="$t('reset')" @click="reset" />
|
||||||
icon="replay"
|
|
||||||
:text="$t('reset')"
|
|
||||||
@click="reset"
|
|
||||||
/>
|
|
||||||
</van-grid>
|
</van-grid>
|
||||||
</demo-block>
|
</demo-block>
|
||||||
</demo-section>
|
</demo-section>
|
||||||
|
@ -64,6 +64,7 @@ export default createComponent({
|
|||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
|
// @exposed-api
|
||||||
start() {
|
start() {
|
||||||
if (this.counting) {
|
if (this.counting) {
|
||||||
return;
|
return;
|
||||||
@ -74,11 +75,13 @@ export default createComponent({
|
|||||||
this.tick();
|
this.tick();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// @exposed-api
|
||||||
pause() {
|
pause() {
|
||||||
this.counting = false;
|
this.counting = false;
|
||||||
cancelRaf(this.rafId);
|
cancelRaf(this.rafId);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// @exposed-api
|
||||||
reset() {
|
reset() {
|
||||||
this.pause();
|
this.pause();
|
||||||
this.remain = this.time;
|
this.remain = this.time;
|
||||||
@ -98,9 +101,15 @@ export default createComponent({
|
|||||||
|
|
||||||
microTick() {
|
microTick() {
|
||||||
this.rafId = raf(() => {
|
this.rafId = raf(() => {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
// in case of call reset immediately after finish
|
||||||
|
if (!this.counting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.setRemain(this.getRemain());
|
this.setRemain(this.getRemain());
|
||||||
|
|
||||||
if (this.remain !== 0) {
|
if (this.remain > 0) {
|
||||||
this.microTick();
|
this.microTick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -108,13 +117,19 @@ export default createComponent({
|
|||||||
|
|
||||||
macroTick() {
|
macroTick() {
|
||||||
this.rafId = raf(() => {
|
this.rafId = raf(() => {
|
||||||
|
/* istanbul ignore if */
|
||||||
|
// in case of call reset immediately after finish
|
||||||
|
if (!this.counting) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const remain = this.getRemain();
|
const remain = this.getRemain();
|
||||||
|
|
||||||
if (!isSameSecond(remain, this.remain) || remain === 0) {
|
if (!isSameSecond(remain, this.remain) || remain === 0) {
|
||||||
this.setRemain(remain);
|
this.setRemain(remain);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.remain !== 0) {
|
if (this.remain > 0) {
|
||||||
this.macroTick();
|
this.macroTick();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user