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
| Prop | Description | Type | Default |
|---|---|---|---|
| v-model / modelValue | Remaining milliseconds (controlled passthrough: the component does not drive itself) | number | — |
| time | Unmanaged total duration in ms (autoStart runs it after mount) | number | — |
| format | Format string (tokens DD/HH/mm/ss/S; without DD, HH carries the total hours) | string | 'HH:mm:ss' |
| autoStart | Start automatically after mount in unmanaged mode | boolean | true |
| millisecond | Refresh every frame (recommended when the millisecond digit is shown) | boolean | false |
| disabled | Disabled (grayed out and pauses the countdown) | boolean | false |
| ariaLabel | Accessible name (falls back to the formatted text when not passed) | string | — |
| sx | sx quick-layout props | LhSxProps | — |
Events
| Event | Description | Callback |
|---|---|---|
| update:modelValue | Controlled value change | (value: number) |
| change | Remaining milliseconds change (per-tick callback in unmanaged mode) | (value: number) |
| finish | Countdown reaches zero | () |
Methods (via ref)
| Method | Description |
|---|---|
| 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 fromariaLabelor the formatted text

