Skip to content
API 风格:

Countdown 倒计时 ​

实时倒计时:墙钟差值驱动(后台切换不漂移),支持受控直显与非受控自走两种模式, 格式化令牌 DD / HH / mm / ss / S。

基础用法 ​

基础用法
02:00:0001:30
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhCountdown } from '@lh-ui/vue3'

const time = ref(2 * 3600 * 1000)
</script>

<template>
<div class="demo-row">
  <LhCountdown :time="time" />
  <LhCountdown :time="90 * 1000" format="mm:ss" />
</div>
</template>
vue
<script>
import { LhCountdown } from '@lh-ui/vue3'

export default {
  components: { LhCountdown },
}
</script>

<template>
<div class="demo-row">
  <LhCountdown :time="2 * 3600 * 1000" />
  <LhCountdown :time="90 * 1000" format="mm:ss" />
</div>
</template>

受控直显 ​

传入 v-model 后组件不自驱动,由外部负责推进(适合配合自己的时钟源)。

受控直显
00:01:00
vue
<script setup lang="ts">
import { ref } from 'vue'
import { LhCountdown, LhButton } from '@lh-ui/vue3'

const controlled = ref(65_000)
</script>

<template>
<div class="demo-row">
  <LhCountdown v-model="controlled" />
  <LhButton size="small" @click="controlled = Math.max(0, controlled - 1000)">-1s</LhButton>
</div>
</template>
vue
<script>
import { LhCountdown, LhButton } from '@lh-ui/vue3'

export default {
  components: { LhCountdown, LhButton },
  data() {
    return { controlled: 65_000 }
  },
}
</script>

<template>
<div class="demo-row">
  <LhCountdown v-model="controlled" />
  <LhButton size="small" @click="controlled = Math.max(0, controlled - 1000)">-1s</LhButton>
</div>
</template>

天 + 毫秒格式与结束回调 ​

DD 天 + 毫秒段
01天02:00:01.500
vue
<script setup lang="ts">
import { LhCountdown } from '@lh-ui/vue3'
</script>

<template>
<LhCountdown :time="26 * 3600 * 1000 + 1500" format="DD天HH:mm:ss.S" millisecond />
</template>
vue
<script>
import { LhCountdown } from '@lh-ui/vue3'

export default {
  components: { LhCountdown },
}
</script>

<template>
<LhCountdown :time="26 * 3600 * 1000 + 1500" format="DD天HH:mm:ss.S" millisecond />
</template>

Countdown API ​

Props ​

属性名说明类型默认值
v-model / modelValue剩余毫秒(受控直显:组件不自驱动)number—
time非受控总时长 ms(挂载后 autoStart 自走)number—
format格式化串(令牌 DD/HH/mm/ss/S;无 DD 时 HH 承载总小时数)string'HH:mm:ss'
autoStart非受控模式挂载后自动开始booleantrue
millisecond逐帧刷新(毫秒位显示时建议开启)booleanfalse
disabled禁用(灰化并暂停计时)booleanfalse
ariaLabel无障碍名称(未传取格式化文案)string—
sx快速布局属性LhSxProps—

Events ​

属性名说明类型
update:modelValue受控值变化(value: number)
change剩余毫秒变化(非受控每步回调)(value: number)
finish倒计时归零()

方法(ref) ​

方法说明
start()开始 / 恢复(暂停点续走)
pause()暂停(记住剩余)
reset()重置回 time 总时长(autoStart 时立即重启)

无障碍 ​

  • 根元素 role="timer",可达名称取 ariaLabel 或格式化文案