debounce

Commons
stable

Wraps a function so that it is only called after the specified delay has elapsed since the last invocation. Accepts a reactive delay (MaybeRef<number>) so the interval can be updated at runtime. The returned wrapper exposes .clear() and .immediate shortcuts.

API

Signature

Signature TypeScript complète, extraite du fichier util.

typescript

API

Paramètres

Paramètres d'entrée acceptés par cet util.

fn
requis
(...args: any[]) => void
The function to debounce.
delay
requis
MaybeRef<number>
Milliseconds to wait after the last call before invoking fn. Accepts a plain number or a Vue ref so the delay can be changed reactively.

API

Valeur de retour

La valeur retournée par cet util.

A debounced wrapper. Call .clear() to cancel a pending invocation. Access .immediate to invoke fn synchronously without debouncing.

Usage

Exemples

Extraits de code prêts à coller.

Debounce a search handler

typescript