Skip to content

useThrottleFn

类别
导出大小
475 B
最近修改
2 days ago
相关

节流函数的执行。对于限制处理器在像调整大小和滚动等事件上的执行频率特别有用。

🌐 Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.

节流阀是一种能触发球的弹簧:球弹出后需要一些时间回缩,因此在准备好之前,它不能再触发球。

示例

Delay is set to 1000ms for this demo.

Button clicked: 0

Event handler called: 0

用法

🌐 Usage

ts
import { 
useThrottleFn
} from '@vueuse/core'
const
throttledFn
=
useThrottleFn
(() => {
// do something, it will be called at most 1 time per second }, 1000) useEventListener(
window
, 'resize',
throttledFn
)

🌐 Recommended Reading