useRafTimeout
useRafTimeout 在指定的时间后执行一个函数,基于 requestAnimationFrame 实现
基础用法
<template>
<div>Hello World! {{ count }}</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { useRafTimeout } from "hooks-vue3";
const count = ref<number>(0);
useRafTimeout(() => {
count.value++;
}, 3000);
</script>
API
useRafTimeout(() => void, time:number);
参数TS类型
export type UseTimeoutFnReturn = {
isRunning: Ref<boolean>; //是否已经触发了
stop: () => void; //取消定时器
start: () => void; //重新执行定时器
};
export type UseTimeoutFnOptions = {
immediate?: boolean;
autoStart?: boolean;
};
function useRafTimeout(
callback: () => void,
delay = 0,
options?: UseTimeoutFnOptions,
): UseTimeoutFnReturn
Last updated