watchThrottled
节流式监视。
Demo
延迟设置为1000毫秒以进行演示。
输入内容:
更新次数: 0
用法
类似于 watch
,但提供了额外的选项 throttle
,该选项将应用于回调函数。
typescript
import { watchThrottled } from '@vueuse/core'
watchThrottled(
source,
() => { console.log('changed!') },
{ throttle: 500 },
)
实质上,它相当于以下代码的简写:
typescript
import { throttleFilter, watchWithFilter } from '@vueuse/core'
watchWithFilter(
source,
() => { console.log('changed!') },
{
eventFilter: throttleFilter(500),
},
)
类型声明
显示类型声明
typescript
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
export { watchThrottled as throttledWatch }
Source
贡献者
Anthony Fu
丶远方
sun0day
Anthony Fu
lvjiaxuan
Joe Zimmerman
webfansplz
变更日志
v10.0.0-beta.4
on 4/13/20234d757
- feat(types)!: rename MaybeComputedRef
to MaybeRefOrGetter