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 或格式化文案