fn
useIntervalFn
testeddemoCall a function on every interval. Supports reactive interval duration, pause/resume, and automatic cleanup on scope dispose.
Examples
ts
const { pause, resume, isActive } = useIntervalFn(() => {
console.log('tick');
}, 1000);ts
// Reactive interval
const delay = ref(1000);
useIntervalFn(() => console.log('tick'), delay);
delay.value = 500; // interval restarts with new durationDemo
Loading demo…
Signature
ts
export function useIntervalFn(
callback: () => void,
interval: MaybeRefOrGetter<number> = 1000,
options: UseIntervalFnOptions ={ ... }Parameters
| Parameter | Type | Description |
|---|---|---|
callback | () => void | Function to call on every interval tick |
interval? | MaybeRefOrGetter<number> | Function to call on every interval tick |
options? | UseIntervalFnOptions | Configuration options |
Returns
UseIntervalFnReturn