Skip to content
API 风格:

Countdown ​

Real-time countdown: driven by wall-clock deltas (no drift when switching background tabs). Supports both a controlled passthrough mode and an unmanaged self-running mode, with format tokens DD / HH / mm / ss / S.

Basic Usage ​

Basic usage
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>

Controlled passthrough ​

Once v-model is passed, the component no longer drives itself — the consumer is responsible for advancing it (useful when pairing with your own clock source).

Controlled passthrough
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>

Days + milliseconds format and finish callback ​

DD days + milliseconds segment
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 ​

PropDescriptionTypeDefault
v-model / modelValueRemaining milliseconds (controlled passthrough: the component does not drive itself)number—
timeUnmanaged total duration in ms (autoStart runs it after mount)number—
formatFormat string (tokens DD/HH/mm/ss/S; without DD, HH carries the total hours)string'HH:mm:ss'
autoStartStart automatically after mount in unmanaged modebooleantrue
millisecondRefresh every frame (recommended when the millisecond digit is shown)booleanfalse
disabledDisabled (grayed out and pauses the countdown)booleanfalse
ariaLabelAccessible name (falls back to the formatted text when not passed)string—
sxsx quick-layout propsLhSxProps—

Events ​

EventDescriptionCallback
update:modelValueControlled value change(value: number)
changeRemaining milliseconds change (per-tick callback in unmanaged mode)(value: number)
finishCountdown reaches zero()

Methods (via ref) ​

MethodDescription
start()Start / resume (continues from the paused point)
pause()Pause (remembers the remaining time)
reset()Reset back to the time total duration (restarts immediately when autoStart is on)

Accessibility ​

  • The root element has role="timer; its accessible name comes from ariaLabel or the formatted text

Beauty of tradition, foundation of code