refThrottled
ref値の変更を調整します。
デモ
このデモでは、遅延が1000msに設定されています。
調整済み
更新回数: 0
Trailing: true
Leading: false
使用方法
js
import { refThrottled } from '@vueuse/core'
const input = ref('')
const throttled = refThrottled(input, 1000)
Trailing
末尾の変更を監視したくない場合は、3番目のパラメーターをfalse
に設定します(デフォルトはtrue
です)。
js
import { refThrottled } from '@vueuse/core'
const input = ref('')
const throttled = refThrottled(input, 1000, false)
Leading
コールバックをすぐに呼び出すことができます(ms
タイムアウトの先頭)。この動作を望まない場合は、4番目のパラメーターをfalse
に設定します(デフォルトはtrue
です)。
js
import { refThrottled } from '@vueuse/core'
const input = ref('')
const throttled = refThrottled(input, 1000, undefined, false)
推奨読書
型宣言
typescript
/**
* Throttle execution of a function. Especially useful for rate limiting
* execution of handlers on events like resize and scroll.
*
* @param value Ref value to be watched with throttle effect
* @param delay A zero-or-greater delay in milliseconds. For event callbacks, values around 100 or 250 (or even higher) are most useful.
* @param [trailing] if true, update the value again after the delay time is up
* @param [leading] if true, update the value on the leading edge of the ms timeout
*/
export declare function refThrottled<T>(
value: Ref<T>,
delay?: number,
trailing?: boolean,
leading?: boolean,
): Ref<T, T>
export { refThrottled as useThrottle, refThrottled as throttledRef }
ソースコード
コントリビューター
変更ログ
v12.0.0-beta.1
2024/11/21