• Parameters

    • initialTime: number = 5

      倒计时时间,单位为秒

    • onFinish: () => void = ...

      倒计时结束回调函数

    Returns {
        resetCountDown: () => void;
        startCountDown: () => void;
        stopCountDown: () => void;
        timeLeft: Ref<number, number>;
    }

    Returns { timeLeft, // 剩余时间 startCountDown, // 开始倒计时 resetCountDown, // 重置倒计时 stopCountDown // 结束倒计时 }

    // 示例用法
    <template>
    <div class=wrap>
    <p>{{ timeLeft }}</p>
    <button @click="startCountDown">开始倒计时</button>
    <button @click="resetCountDown">重置倒计时</button>
    <button @click="stopCountDown">结束倒计时</button>
    </div>
    </template>

    <script lang="ts" setup>
    import useCountDown from '@/dlf/un/use-count-down'

    // 5秒倒计时
    const { timeLeft,
    startCountDown,
    resetCountDown,
    stopCountDown
    } = useCountDown(5, () => {
    console.log('倒计时结束')
    });
    </script>