Skip to content
API 风格:

Countdown 카운트다운 ​

실시간 카운트다운: 벽시계 차이값으로 구동합니다(백그라운드 전환 시에도 어긋나지 않음). 제어형 직접 표시와 비제어형 자동 실행 두 가지 모드를 지원하며, 포맷 토큰 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비제어형 모드에서 마운트 후 자동 시작booleantrue
millisecond매 프레임 새로고침(밀리초 자리를 표시할 때 활성화를 권장)booleanfalse
disabled비활성화(회색 표시 및 카운트다운 일시 정지)booleanfalse
ariaLabel접근성 이름(미전달 시 포맷팅된 문구 사용)string—
sxsx 빠른 레이아웃 속성LhSxProps—

Events ​

속성설명타입
update:modelValue제어형 값 변화(value: number)
change남은 밀리초 변화(비제어형 매 스텝 콜백)(value: number)
finish카운트다운 0 도달()

메서드(ref) ​

메서드설명
start()시작 / 재개(일시 정지 지점부터 계속)
pause()일시 정지(남은 시간 기억)
reset()time 총 시간으로 리셋(autoStart일 때 즉시 재시작)

접근성 ​

  • 루트 요소 role="timer", 접근성 이름은 ariaLabel 또는 포맷팅된 문구를 사용합니다

국풍의 아름다움으로 코드의 토대를 세웁니다