useRafInterval
useRafInterval 定时执行一个函数,基于 requestAnimationFrame 实现
基础用法
<template>
<div>Hello World! {{ count }}</div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { useRafInterval } from "hooks-vue3";
const count = ref<number>(0);
useRafInterval(() => {
count.value++;
}, 3000);
</script>
API
useRafInterval(() => void, time:number);
参数TS类型
export type UseIntervalFnReturn = {
isRunning: Ref<boolean>;
start: () => void; //开始定时器
stop: () => void; //停止定时器
};
export type UseIntervalFnOptions = {
immediate?: boolean;
autoStart?: boolean;
};
function useRafInterval(
callback: () => void,
delay = 0,
options?: UseIntervalFnOptions,
): UseIntervalFnReturn
Last updated