Skip to content

useTimeoutPoll

类别
导出体积
414 B
上次更改
7 months ago

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

示例

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)

类型声明

ts
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

源码

源码演示文档

贡献者

一纸忘忧
Anthony Fu
Anthony Fu
IlyaL
Robin
Hongkun
OrbisK
Sebastien
David Vallejo
jiadesen
sun0day
Jelf
Wenlu Wang

更新日志

7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
64c53 - feat(useTimtoutFn,useTimeoutPoll): align behavior (#4543)
a5fb0 - fix: only start by default at client
0450d - fix: immediate default value should be true (#4232)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
7a897 - fix: unexpected immediate execution (#3159)