import{o as n,a,y as t}from"./vue-libs.b44bc779.js";const l={class:"van-doc-markdown-body"},e=t(`

useCountDown

Intro

Used to manage the countdown.

Usage

Basic Usage

<span>Total time\uFF1A{{ current.total }}</span>
<span>Remain days\uFF1A{{ current.days }}</span>
<span>Remain hours\uFF1A{{ current.hours }}</span>
<span>Remain minutes\uFF1A{{ current.minutes }}</span>
<span>Remain seconds\uFF1A{{ current.seconds }}</span>
<span>Remain milliseconds\uFF1A{{ current.milliseconds }}</span>
import { useCountDown } from '@vant/use';

export default {
  setup() {
    const countDown = useCountDown({
      time: 24 * 60 * 60 * 1000,
    });

    countDown.start();

    return {
      current: countDown.current,
    };
  },
};

Millisecond

import { useCountDown } from '@vant/use';

export default {
  setup() {
    const countDown = useCountDown({
      time: 24 * 60 * 60 * 1000,
      millisecond: true,
    });
    countDown.start();

    return {
      current: countDown.current,
    };
  },
};

API

Type Declarations

type CurrentTime = {
  days: number;
  hours: number;
  total: number;
  minutes: number;
  seconds: number;
  milliseconds: number;
};

type CountDown = {
  start: () => void;
  pause: () => void;
  reset: (totalTime: number) => void;
  current: ComputedRef<CurrentTime>;
};

type UseCountDownOptions = {
  time: number;
  millisecond?: boolean;
  onChange?: (current: CurrentTime) => void;
  onFinish?: () => void;
};

function useCountDown(options: UseCountDownOptions): CountDown;

Params

NameDescriptionTypeDefault Value
timeTotal time, unit millisecondsnumber-
millisecondWhether to enable millisecond renderbooleanfalse
onChangeTriggered when count down changed(current: CurrentTime) => void-
onFinishTriggered when count down finished-

Return Value

NameDescriptionType
currentCurrent remain timeCurrentTime
startStart count down() => void
pausePause count down() => void
resetReset count down(time?: number): void

CurrentTime Structure

NameDescriptionType
totalTotal time, unit millisecondsnumber
daysRemain daysnumber
hoursRemain hoursnumber
minutesRemain minutesnumber
secondsRemain secondsnumber
millisecondsRemain millisecondsnumber
`,10),p=[e],h={__name:"use-count-down.en-US",setup(c,{expose:s}){return s({frontmatter:{}}),(r,i)=>(n(),a("div",l,p))}};export{h as default};