Problem Statement
How do you avoid memory leaks when using watchers and effects in composables?
Explanation
Always rely on Vue’s automatic cleanup: watchers and watchEffects created in setup() are disposed when the component unmounts. For manual resources (timers, sockets), tie cleanup to onUnmounted and expose a stop() if the caller needs early disposal.
Code Solution
SolutionRead Only
const t = setInterval(tick, 1000) onUnmounted(() => clearInterval(t))