Skip to content

Countdown 倒计时

用于活动截止、支付剩余时间、任务时限等场景,支持目标时间、毫秒刷新、自定义格式与手动控制。

基础用法

vue
<lk-countdown :time="30 * 60 * 1000" />

目标时间

vue
<lk-countdown
  :target-time="Date.now() + 2 * 60 * 60 * 1000"
  format="HH:mm:ss"
  type="danger"
  variant="card"
  size="lg"
/>

自定义格式

vue
<lk-countdown :time="26 * 60 * 60 * 1000" format="DD天 HH:mm:ss" />
<lk-countdown :time="90 * 1000" format="ss.SS秒" millisecond />

手动控制

vue
<template>
  <lk-countdown ref="countdownRef" :time="20000" :auto-start="false" @finish="onFinish" />
  <lk-button @tap="countdownRef?.start()">开始</lk-button>
  <lk-button @tap="countdownRef?.pause()">暂停</lk-button>
  <lk-button @tap="countdownRef?.reset(true)">重置</lk-button>
</template>

API

Props

参数说明类型默认值
time剩余时长,单位 msnumber0
targetTime截止时间,时间戳或日期字符串number / string''
format展示格式,支持 DD/HH/mm/ss/SSS 等占位string'HH:mm:ss'
autoStart是否自动开始booleantrue
millisecond是否毫秒级刷新booleanfalse
padZero是否补零booleantrue
trimZeroDay是否隐藏 0 天booleanfalse
showZero结束后是否保留 00:00:00booleantrue
type语义色default / primary / success / warning / danger / infodefault
variant视觉形态plain / block / cardblock
size尺寸sm / md / lgmd
prefix前缀文本string''
suffix后缀文本string''
unitMap单位文本映射object{}
formatter自定义格式化函数(timeData) => string / numbernull

Events

事件名说明回调参数
start开始时触发-
pause暂停时触发(remaining: number)
reset重置时触发(remaining: number)
finish倒计时结束时触发-
change时间变化时触发(timeData: CountdownTimeData)

Slots

插槽名说明作用域参数
default自定义展示内容{ timeData }

Methods

方法名说明
start()开始倒计时
pause()暂停倒计时
reset(autoStart?: boolean)重置倒计时

Demo

项目演示位于 src/components/demos/countdown-demo.vue

基于 MIT 协议开源 · 粤ICP备2022114240号-3

Countdown 倒计时

正在连接预览服务...

请先运行 pnpm run dev:h5