跳到主要内容

useTimeoutPoll

分类
导出大小
414 B
上次更改
8 个月前

使用 timeout 进行轮询。它将在上一个任务完成后触发回调。

演示

计数: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
++
} // Only trigger after last fetch is done 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
王文路

更新日志

v12.8.0
7432f - feat(types): 废弃 MaybeRefMaybeRefOrGetter,转而使用 Vue 的原生类型 (#4636)
v12.6.0
64c53 - feat(useTimtoutFn,useTimeoutPoll): 统一行为 (#4543)
v12.3.0
a5fb0 - fix: 默认只在客户端启动
0450d - fix: `immediate` 默认值应为 `true` (#4232)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.2.1
7a897 - fix: 意外的立即执行 (#3159)

根据 MIT 许可证发布。