useInterval
定时器Hook
前置依赖
依赖参数
| 参数名 | 类型 | 说明 |
|---|---|---|
deps.vue.ref | <T>(value: T) => Ref<T> | Vue的ref函数 |
deps.vue.onUnmounted | (fn: () => void) => void | Vue的onUnmounted钩子 |
deps.setInterval | typeof setInterval | 设置定时器函数 |
deps.clearInterval | typeof clearInterval | 清除定时器函数 |
使用示例
typescript
import { ref, onUnmounted } from 'vue'
import { useInterval } from 'zcw-shared/hooks/useInterval'
const { isActive, pause, resume } = useInterval(
() => {
console.log('每秒执行')
},
1000,
{ immediate: true },
{
vue: { ref, onUnmounted },
setInterval,
clearInterval
}
)
// 暂停
pause()
// 恢复
resume()