UNPKG

@daysnap/horn-use

Version:
20 lines (19 loc) 510 B
import { ref } from 'vue'; export const useCountDown = (start) => { const countRef = ref(0); let timer = null; const trigger = (st) => { clearTimeout(timer); let loop; (loop = (count) => { countRef.value = count; if (count <= 0) { countRef.value = 0; return; } count--; timer = setTimeout(loop, 1000, count); })(st ?? start ?? 60); }; return [countRef, trigger]; };