Skip to content

watchThrottled

类别
导出体积
531 B
上次更改
5 days ago
别名
throttledWatch

节流式监视。

示例

延迟设置为1000毫秒以进行演示。

输入内容:

更新次数: 0

用法

类似于 watch,但提供了额外的选项 throttle,该选项将应用于回调函数。

ts
import { 
watchThrottled
} from '@vueuse/core'
watchThrottled
(
source, () => {
console
.
log
('changed!') },
{
throttle
: 500 },
)

实质上,它相当于以下代码的简写:

ts
import { 
throttleFilter
,
watchWithFilter
} from '@vueuse/core'
watchWithFilter
(
source, () => {
console
.
log
('changed!') },
{
eventFilter
:
throttleFilter
(500),
}, )

类型声明

显示类型声明
ts
export interface 
WatchThrottledOptions
<
Immediate
>
extends WatchOptions<
Immediate
> {
throttle
?:
MaybeRefOrGetter
<number>
trailing
?: boolean
leading
?: boolean
} export declare function
watchThrottled
<
T
extends
Readonly
<
WatchSource
<unknown>[]>,
Immediate
extends
Readonly
<boolean> = false,
>(
sources
: [...
T
],
cb
:
WatchCallback
<
MapSources
<
T
>,
MapOldSources
<
T
,
Immediate
>>,
options
?:
WatchThrottledOptions
<
Immediate
>,
):
WatchStopHandle
export declare function
watchThrottled
<
T
,
Immediate
extends
Readonly
<boolean> = false,
>(
source
:
WatchSource
<
T
>,
cb
:
WatchCallback
<
T
,
Immediate
extends true ?
T
| undefined :
T
>,
options
?:
WatchThrottledOptions
<
Immediate
>,
):
WatchStopHandle
export declare function
watchThrottled
<
T
extends object,
Immediate
extends
Readonly
<boolean> = false,
>(
source
:
T
,
cb
:
WatchCallback
<
T
,
Immediate
extends true ?
T
| undefined :
T
>,
options
?:
WatchThrottledOptions
<
Immediate
>,
):
WatchStopHandle
/** @deprecated use `watchThrottled` instead */ export declare const
throttledWatch
: typeof
watchThrottled

源码

源码演示文档

贡献者

一纸忘忧
Anthony Fu
Anthony Fu
sun0day
Vida Xie
IlyaL
OrbisK
丶远方
lvjiaxuan
Joe Zimmerman
webfansplz

更新日志

e5f74 - feat!: deprecate alias exports in favor of original function names (#5009)
7432f - feat(types): deprecate MaybeRef and MaybeRefOrGetter in favor of Vue's native (#4636)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)