Skip to content

useTimeoutPoll

使用超时来轮询某些内容。它将在最后一个任务完成后触发回调。

¥Use timeout to poll something. It will trigger callback after last task is done.

示例

Count: 0
isActive: false

用法

¥Usage

ts
import { useTimeoutPoll } from '@vueuse/core'

const count = ref(0)

async function fetchData() {
  await new Promise(resolve => setTimeout(resolve, 1000))
  count.value++
}

// Only trigger after last fetch is done
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)

类型声明

typescript
export declare function useTimeoutPoll(
  fn: () => Awaitable<void>,
  interval: MaybeRefOrGetter<number>,
  options?: UseTimeoutFnOptions,
): Pausable

源代码

源代码示例文档

变更日志

v12.3.0 on 1/2/2025
a5fb0 - fix: only start by default at client
0450d - fix: immediate default value should be true (#4232)

VueUse 中文网 - 粤ICP备13048890号