useIntervalFn
带有控制功能的 setInterval
包装器
Demo
使用方法
js
import { useIntervalFn } from '@vueuse/core'
const { pause, resume, isActive } = useIntervalFn(() => {
/* 你的函数 */
}, 1000)
Type Declarations
typescript
export interface UseIntervalFnOptions {
/**
* Start the timer immediately
*
* @default true
*/
immediate?: boolean
/**
* Execute the callback immediately after calling `resume`
*
* @default false
*/
immediateCallback?: boolean
}
/**
* Wrapper for `setInterval` with controls
*
* @param cb
* @param interval
* @param options
*/
export declare function useIntervalFn(
cb: Fn,
interval?: MaybeRefOrGetter<number>,
options?: UseIntervalFnOptions,
): Pausable