useToggleScope

Commons
stable

Conditionally activates a Vue effectScope driven by a reactive boolean source. When the source turns true the scope starts (running the provided callback inside it); when it turns false the scope is stopped and discarded. The scope is also stopped on parent scope dispose.

API

Signature

Signature TypeScript complète extraite du fichier du composable.

typescript

useToggleScope is a low-level primitive used internally by useVModel, useValidation, and other composables that need conditional effect trees. Prefer those higher-level composables for typical use cases.

API

Paramètres

Paramètres d'entrée acceptés par ce composable.

source
requis
WatchSource<boolean>
Reactive boolean source (ref, computed, or getter). When it evaluates to true the scope is started; when false the scope is stopped.
fn
requis
(reset: () => void) => void
Callback run inside the new effectScope. Receives a `reset()` function that can be called from inside the scope to stop the current scope and immediately restart it — useful for subscriptions that need to re-initialise when an inner condition changes.

Usage

Exemples

Extraits de code prêts à coller.

Run a watcher only while a panel is open

vue

Reset the scope when a sub-condition changes

vue