Countdown
Real-time countdown driven by wall-clock deltas (no drift after background switches), with controlled direct display and uncontrolled self-driving modes, and format tokens DD / HH / mm / ss / S.
Basic usage
vue
<template>
<lh-countdown :time="2 * 3600 * 1000" />
</template>Custom format (days + milliseconds)
vue
<template>
<lh-countdown
:time="26 * 3600 * 1000 + 1500"
format="DD天HH:mm:ss.S"
millisecond
/>
</template>Controlled direct display
Once v-model is bound, the component stops self-driving; the outside is responsible for advancing it (suitable for pairing with your own clock source).
vue
<template>
<lh-countdown v-model="controlled" @finish="onFinish" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const controlled = ref(65_000)
function onFinish() {
// reached zero
}
</script>Props
| Prop | Description | Type | Default |
|---|---|---|---|
| v-model / modelValue | Remaining ms (controlled direct display) | number | — |
| time | Uncontrolled total duration ms (auto-starts on mount when autoStart) | number | — |
| format | Format string (tokens DD/HH/mm/ss/S; without DD, HH carries total hours) | string | 'HH:mm:ss' |
| autoStart | Auto-start on mount in uncontrolled mode | boolean | true |
| millisecond | Per-frame updates (recommended when showing milliseconds) | boolean | false |
| disabled | Disabled (greyed and pauses ticking) | boolean | false |
| ariaLabel | Accessible name (falls back to formatted text) | string | — |
| customClass | Custom class (root node) | string | — |
| sx | Shorthand layout props | — | — |
Events
| Event | Description | Payload |
|---|---|---|
| update:modelValue | Controlled two-way binding | (value: number) |
| change | Remaining ms changed (each tick in uncontrolled mode) | (value: number) |
| finish | Countdown reached zero | — |
Methods (ref)
| Method | Description |
|---|---|
| start() | Start / resume (continues from the paused point) |
| pause() | Pause (keeps the remaining time) |
| reset() | Reset to the time total (restarts immediately when autoStart) |
Accessibility
- Root element
role="timer", accessible name fromariaLabelor the formatted text

