Skip to content

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 ​

PropDescriptionTypeDefault
v-model / modelValueRemaining ms (controlled direct display)number—
timeUncontrolled total duration ms (auto-starts on mount when autoStart)number—
formatFormat string (tokens DD/HH/mm/ss/S; without DD, HH carries total hours)string'HH:mm:ss'
autoStartAuto-start on mount in uncontrolled modebooleantrue
millisecondPer-frame updates (recommended when showing milliseconds)booleanfalse
disabledDisabled (greyed and pauses ticking)booleanfalse
ariaLabelAccessible name (falls back to formatted text)string—
customClassCustom class (root node)string—
sxShorthand layout props——

Events ​

EventDescriptionPayload
update:modelValueControlled two-way binding(value: number)
changeRemaining ms changed (each tick in uncontrolled mode)(value: number)
finishCountdown reached zero—

Methods (ref) ​

MethodDescription
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 from ariaLabel or the formatted text