effectScope()

Groups reactive effects so they can be disposed together.

Since Vue 3.2 Spec ↗

Syntax

effectScope(detached?): EffectScope

Parameters

NameTypeRequiredDescription
detached boolean No If true, the scope is not collected by a parent scope.

Returns

EffectScope — Scope with run() and stop() methods.

Examples

<script setup lang="ts">
import { effectScope, ref, watchEffect } from 'vue';

const scope = effectScope();
scope.run(() => {
  const count = ref(0);
  watchEffect(() => console.log(count.value));
});

// later, stop all effects created in the scope at once:
scope.stop();
</script>

Notes

effectScope captures computed, watch, and watchEffect created inside its run() callback so a single stop() disposes them all. Used by libraries and advanced composables to manage effect lifetimes outside a component. Use onScopeDispose() to register cleanup within a scope.