Countdown カウントダウン
リアルタイムカウントダウン:壁時計との差分で駆動(バックグラウンド切り替えでもずれない)、制御付き直表示と非制御の自動進行の 2 モードをサポートし、 フォーマットトークン DD / HH / mm / ss / S を使用します。
基本的な使い方
基本的な使い方
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>制御付き直表示
v-model を渡すとコンポーネントは自動で進行せず、外部が進行を担います(独自の時計源と組み合わせる場合に適しています)。
制御付き直表示
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>日 + ミリ秒フォーマットと終了コールバック
DD 日 + ミリ秒
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
| プロパティ名 | 説明 | 型 | デフォルト値 |
|---|---|---|---|
| v-model / modelValue | 残りミリ秒(制御付き直表示:コンポーネントは自動で進行しない) | number | — |
| time | 非制御の総時間 ms(マウント後 autoStart で自動進行) | number | — |
| format | フォーマット文字列(トークン DD/HH/mm/ss/S。DD がない場合 HH が総時間数を保持) | string | 'HH:mm:ss' |
| autoStart | 非制御モードでマウント後に自動開始 | boolean | true |
| millisecond | フレームごとの更新(ミリ秒桁を表示する場合は有効を推奨) | boolean | false |
| disabled | 無効(グレーアウトして計測を一時停止) | boolean | false |
| ariaLabel | アクセシビリティ名(未指定時はフォーマット済みテキストを使用) | string | — |
| sx | クイックレイアウトプロパティ | LhSxProps | — |
Events
| イベント名 | 説明 | 型 |
|---|---|---|
| update:modelValue | 制御値の変化 | (value: number) |
| change | 残りミリ秒の変化(非制御で毎ステップのコールバック) | (value: number) |
| finish | カウントダウンがゼロに到達 | () |
メソッド(ref)
| メソッド | 説明 |
|---|---|
| start() | 開始 / 再開(一時停止した位置から再開) |
| pause() | 一時停止(残り時間を保持) |
| reset() | time の総時間にリセット(autoStart の場合は即時に再開) |
アクセシビリティ
- ルート要素は
role="timer"。アクセシブル名はariaLabelまたはフォーマット済みテキスト

