Intro

The logic for Countdown.

倒计时通用逻辑。

Demos

API

index.d.ts
import type { ComputedRef, Ref } from 'vue';
import type { CalculatedDuration } from './functions';
export declare type Duration = {
    days: number;
    hours: number;
    minutes: number;
    seconds: number;
    milliseconds: number;
};
declare type CountDownPropsBase = {
    /**
     * @description 初始剩余毫秒数
     */
    remain: number;
    onEnd?: () => void;
    format?: string;
    onChange?: (t: Duration) => void;
};
declare type CountDownProps<Controls extends boolean> = CountDownPropsBase & {
    /**
     * @description 手动开始,默认自动开始
     */
    manual?: Controls;
};
declare type CountDownReturnBase = {
    remain: Ref<number>;
    calculated: ComputedRef<CalculatedDuration>;
    formattedText: Ref<string | undefined>;
    running: Ref<boolean>;
};
declare type CountDownReturnControlls = {
    resume: () => void;
    pause: () => void;
    reset: () => void;
};
declare function useCountDown(props: CountDownProps<false>): CountDownReturnBase;
declare function useCountDown(props: CountDownProps<true>): CountDownReturnBase & CountDownReturnControlls;
export * from './functions';
export { useCountDown };
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
functions.d.ts
import type { Duration } from '.';
export declare type CalculatedDuration = Record<string, number>;
export declare function calculateDuration(time: Duration, format?: string): CalculatedDuration;
export declare function formatDuration(time: CalculatedDuration, format?: string): string;
1
2
3
4