Skip to content

CountDown

Used to display countdown values in real-time, supporting millisecond-level rendering and manual control.

Component Type

Basic Usage

time represents the total countdown duration, unit is milliseconds.

html
<wd-count-down :time="time" />
ts
const time = ref<number>(30 * 60 * 60 * 1000)

Component Variant

Custom Format

Customize display format through format.

html
<wd-count-down :time="time" format="DD Days HH Hours mm Minutes ss Seconds" />

Millisecond-level Rendering

Set millisecond to enable millisecond-level rendering.

html
<wd-count-down :time="time" millisecond format="HH:mm:ss:SS" />

Component Style

Custom Style

Use default slot to customize countdown content, slot parameters see TimeData below.

html
<wd-count-down :time="time">
  <template #default="{ current }">
    <span class="custom-count-down">{{ current.hours }}</span>
    <span class="custom-count-down-colon">:</span>
    <span class="custom-count-down">{{ current.minutes }}</span>
    <span class="custom-count-down-colon">:</span>
    <span class="custom-count-down">{{ current.seconds }}</span>
  </template>
</wd-count-down>

Special Style

Manual Control

Control start, pause, reset through instance methods.

html
<wd-count-down ref="countDown" :time="3000" millisecond :auto-start="false" format="ss:SSS" @finish="onFinish" />
<wd-grid clickable border>
  <wd-grid-item text="Start" icon="play-circle" @click="start" />
  <wd-grid-item text="Pause" icon="pause-circle" @click="pause" />
  <wd-grid-item text="Reset" icon="refresh" @click="reset" />
</wd-grid>
ts
const countDown = ref<CountDownInstance>()

const start = () => countDown.value?.start()
const pause = () => countDown.value?.pause()
const reset = () => countDown.value?.reset()

Attributes

ParameterDescriptionTypeDefault Value
timeCountdown duration, unit millisecondsnumber-
millisecondWhether to enable millisecond-level renderingbooleanfalse
formatCountdown format stringstringHH:mm:ss
auto-startWhether to automatically start countdown after initialization and resetbooleantrue
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Events

Event NameDescriptionParameters
changeTriggered when countdown changescurrent: TimeData
finishTriggered when countdown ends-

Methods

Method NameDescriptionParameters
startStart countdown-
pausePause countdown-
resetReset countdown; if auto-start is true, automatically start after reset-

Slots

nameDescriptionParameters
defaultCustom countdown display content{ current: TimeData }

format Format

FormatDescription
DDDays
HHHours
mmMinutes
ssSeconds
SMilliseconds (1 digit)
SSMilliseconds (2 digits)
SSSMilliseconds (3 digits)

TimeData Object

PropertyDescriptionType
totalRemaining total millisecondsnumber
daysDaysnumber
hoursHoursnumber
minutesMinutesnumber
secondsSecondsnumber
millisecondsMillisecondsnumber

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-count-down-text-color$text-main倒计时文本颜色
--wot-count-down-font-size$typography-body-size-main倒计时文本字号
--wot-count-down-line-height$typography-body-line--height-size-main倒计时文本行高

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.