useCountdown
useCountdown 倒计时功能,接受一个目标倒计时数字,返回倒计时的各种方法
实现代码
html
<button @click="startCountDown">
{{currentCount===60?'开启60秒倒计时':currentCount}}</button
><br /><br />
<button @click="stopCountDown">停止倒计时</button><br /><br />
<button @click="resetCountDown">重置倒计时</button>tsx
import { Button } from '@aplus-frontend/antdv';
import { useCountdown } from './index';
const { currentCount, start, reset, stop } = useCountdown(60);
const startCountDown = () => {
start();
};
const stopCountDown = () => {
stop();
};
const resetCountDown = () => {
reset();
};API
| 属性 | 描述 | 类型 | 默认值 |
|---|---|---|---|
| count | 倒计时数字 | number | - |
Type Declarations
jsx
function useCountdown(count: number): {
start: () => void;
reset: () => void;
restart: () => void;
clear: () => void;
stop: () => void;
currentCount: Ref<number>;
isStart: Ref<boolean>;
}