# Countdown
A live countdown driven by wall-clock deltas (no drift when the tab goes to the background), supporting both a controlled display mode and an uncontrolled self-running mode, with the format tokens DD / HH / mm / ss / S.
Countdown
<template>
<div class="demo-col" style="gap: 18px">
<div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: baseline">
<LhCountdown :time="2 * 3600 * 1000" />
<LhCountdown :time="90 * 1000" format="mm:ss" />
<LhCountdown :time="26 * 3600 * 1000 + 1500" format="DD天HH:mm:ss.S" millisecond />
</div>
<div class="demo-row" style="gap: 24px; flex-wrap: wrap; align-items: baseline">
<LhCountdown v-model="controlled" />
<LhButton size="small" @click="controlled = Math.max(0, controlled - 1000)">-1s</LhButton>
<span class="demo-note">Controlled display: {{ controlled }}ms (the component does not drive itself)</span>
</div>
</div>
</template>
<script>
export default {
data: () => ({
controlled: 65000,
}),
}
</script>
# Props
| Prop | Description | Type | Default |
|---|---|---|---|
| v-model / modelValue | Remaining milliseconds (controlled display: the component does not drive itself; Vue 2 uses the modelValue prop + input event) | number | — |
| time | Uncontrolled total duration in ms (self-runs on mount via autoStart) | 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 uncontrolled mode | boolean | true |
| millisecond | Refresh every frame (recommended when the millisecond digits are shown) | boolean | false |
| disabled | Disabled (grayed out and pauses the timer) | boolean | false |
| ariaLabel | Accessibility name (falls back to the formatted text) | string | — |
| sx | sx shorthand layout props | — | — |
# Events
| Event | Description | Callback args |
|---|---|---|
| input | v-model event (controlled display) | (value: number) |
| change | Remaining-milliseconds change (per-tick callback in uncontrolled mode) | (value: number) |
| finish | Emitted when the countdown reaches zero | () |
# Methods
| Method | Description |
|---|---|
| start() | Start / resume (continues from the paused point) |
| pause() | Pause (remembers the remaining time) |
| reset() | Reset back to the time duration (restarts immediately when autoStart is on) |
# Accessibility
- Root element
role="timer"; the accessible name comes fromariaLabelor the formatted text
Copyright © 2024-2026 FengMo WenXue