effectScope() Group Effects into a Scope

Last updated: 2026-10-22

effectScope() Group Effects into a Scope

effectScope() groups watchers and computed into one scope that starts and stops as a unit — no per-effect stop bookkeeping.

GroupReactivity: Advanced
KindAPI
ScopeComponent
Vue Version3.0+
SSR SupportYes

📝 Syntax

const scope = effectScope()
scope.run(() => {
  watch(a, fn)
  watchEffect(fn2)
})
scope.stop()   // stops every effect inside

⚙️ Arguments

detachedtrue detaches from the parent scope (default false)

Returns:A scope with run, stop, on, off, pause and resume

▶ Example

Edit the code below and see the live result:

Output:

Both logs follow changes until stopAll() is clicked, then neither updates.

💡 Key Points

💡 Tip Use it in composables so callers hold a single handle to dispose everything.
ℹ️ Note Effects attach to the component scope by default; detached scopes outlive components.
⚠️ Warning Only effects created inside run() belong to the scope.
More case studies coming soon.

📚 Related Tutorials

❓ FAQ

Q Can I skip it?
A Fine for one effect; scopes cut boilerplate when managing many.
Q When to use detached?
A For state that outlives components, such as store internals.
Q Can it be paused?
A 3.4+ adds pause()/resume() for all effects in the scope.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏