# demo-02-scope 用 `effectScope` 模拟组件生命周期:scope 内注册的 watch 与清理函数, 在 `scope.stop()` 时一起释放;释放后 watcher 不再触发。 ## 运行 ```bash pnpm --filter @tutorial/24-vue3-rewrite-demo-02-scope start ``` ## 验证 ```bash pnpm --filter @tutorial/24-vue3-rewrite-demo-02-scope smoke # {"evt":"smoke","ok":true,"log":["watch:1","watch:2","dispose"],"count":3} ``` ## 说明 - `onScopeDispose` 是 `onUnmounted` 的底层机制之一。 - `flush: "sync"` 让回调同步执行,便于在 Node 里断言。 - 组件卸载后取消订阅,避免窗口重载后同一批次被处理两次。 ## 已知限制 - 不覆盖 KeepAlive 的 activated/deactivated。