主题
useThrottleFn
节流函数的执行。对于限制处理器在像调整大小和滚动等事件上的执行频率特别有用。
🌐 Throttle execution of a function. Especially useful for rate limiting execution of handlers on events like resize and scroll.
节流阀是一种能触发球的弹簧:球弹出后需要一些时间回缩,因此在准备好之前,它不能再触发球。
示例
用法
🌐 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