Skip to content

CountDown - Vant 4

CountDown

Intro

Used to display the countdown value in real time, and precision supports milliseconds.

Install

Register component globally via app.use, refer to Component Registration for more registration ways.

js
import { createApp } from'vue'; import { CountDown } from'vant'; const app = createApp(); app.use(CountDown);

Usage

Basic Usage

html
js
import { ref } from'vue'; exportdefault { setup() { const time = ref(30 * 60 * 60 * 1000); return { time }; }, };

Custom Format

html

Millisecond

html

Custom Style

html

Manual Control

html
js
import { showToast } from'vant'; exportdefault { setup() { const countDown = ref(null); conststart = () => { countDown.value.start(); }; constpause = () => { countDown.value.pause(); }; constreset = () => { countDown.value.reset(); }; constonFinish = () => showToast('Finished'); return { start, pause, reset, onFinish, countDown, }; }, };

API

Props

AttributeDescriptionTypeDefault
timeTotal time, unit milliseconds*numberstring*
formatTime formatstringHH:mm:ss
auto-startWhether to auto start count downbooleantrue
millisecondWhether to enable millisecond renderbooleanfalse

Available formats

FormatDescription
DDDay
HHHour
mmMinute
ssSecond
SMillisecond, 1-digit
SSMillisecond, 2-digits
SSSMillisecond, 3-digits

Events

EventDescriptionArguments
finishEmitted when count down finished-
changeEmitted when count down changedcurrentTime: CurrentTime

Slots

NameDescriptionSlotProps
defaultCustom ContentcurrentTime: CurrentTime

CurrentTime Structure

NameDescriptionType
totalTotal time, unit millisecondsnumber
daysRemain daysnumber
hoursRemain hoursnumber
minutesRemain minutesnumber
secondsRemain secondsnumber
millisecondsRemain millisecondsnumber

Methods

Use ref to get CountDown instance and call instance methods.

NameDescriptionAttributeReturn value
startStart count down--
pausePause count down--
resetReset count down--

Types

The component exports the following type definitions:

ts
importtype { CountDownProps, CountDownInstance, CountDownCurrentTime, } from'vant';

CountDownInstance is the type of component instance:

ts
import { ref } from'vue'; importtype { CountDownInstance } from'vant'; const countDownRef = ref<CountDownInstance>(); countDownRef.value?.start();

Theming

CSS Variables

The component provides the following CSS variables, which can be used to customize styles. Please refer to ConfigProvider component.

NameDefault ValueDescription
--van-count-down-text-colorvar(--van-text-color)-
--van-count-down-font-sizevar(--van-font-size-md)-
--van-count-down-line-heightvar(--van-line-height-md)-

Enterprise-level mobile solution based on Vant