Skip to content

useTimeoutPoll

Category
Export Size
411 B
Last Changed
3 hours ago

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

Demo

Count: 0
isActive: false

用法

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

const count = ref(0)

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

// 仅在最后一个获取完成后触发
const { isActive, pause, resume } = useTimeoutPoll(fetchData, 1000)

Type Declarations

typescript
export interface UseTimeoutPollOptions {
  /**
   * Start the timer immediately
   *
   * @default true
   */
  immediate?: boolean
  /**
   * Execute the callback immediately after calling `resume`
   *
   * @default false
   */
  immediateCallback?: boolean
}
export declare function useTimeoutPoll(
  fn: () => Awaitable<void>,
  interval: MaybeRefOrGetter<number>,
  options?: UseTimeoutFnOptions,
): Pausable

Source

SourceDemoDocs

Contributors

jorshen

Changelog

No recent changes

Released under the MIT License.