Skip to content

CountDown 倒计时 ​

用于实时展示倒计时数值,支持毫秒级渲染与手动控制。

组件类型 ​

基础用法 ​

time 表示倒计时总时长,单位毫秒。

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

组件变体 ​

自定义格式 ​

通过 format 自定义展示格式。

html
<wd-count-down :time="time" format="DD 天 HH 时 mm 分 ss 秒" />

毫秒级渲染 ​

设置 millisecond 开启毫秒级渲染。

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

组件样式 ​

自定义样式 ​

使用默认插槽自定义倒计时内容,插槽参数见下方 TimeData。

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>

特殊样式 ​

手动控制 ​

通过实例方法控制开始、暂停、重置。

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="开始" icon="play-circle" @click="start" />
  <wd-grid-item text="暂停" icon="pause-circle" @click="pause" />
  <wd-grid-item text="重置" 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 ​

参数说明类型默认值
time倒计时时长,单位毫秒number-
millisecond是否开启毫秒级渲染booleanfalse
format倒计时格式化字符串stringHH:mm:ss
auto-start是否在初始化和重置后自动开始倒计时booleantrue
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

Events ​

事件名称说明参数
change倒计时变化时触发current: TimeData
finish倒计时结束时触发-

Methods ​

方法名说明参数
start开始倒计时-
pause暂停倒计时-
reset重置倒计时;若 auto-start 为 true,重置后自动开始-

Slots ​

name说明参数
default自定义倒计时展示内容{ current: TimeData }

format 格式 ​

格式说明
DD天数
HH小时
mm分钟
ss秒数
S毫秒(1 位)
SS毫秒(2 位)
SSS毫秒(3 位)

TimeData 对象 ​

属性说明类型
total剩余总毫秒数number
days天number
hours小时number
minutes分钟number
seconds秒number
milliseconds毫秒number

主题定制 ​

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倒计时文本行高

源代码 ​

文档
• 组件

Released under the MIT License.

Released under the MIT License.