Performance: Effective scope for cleanup
MEDIUM IMPACT
This concept affects how efficiently Vue components release resources and avoid memory leaks, impacting long-term page responsiveness and stability.
import { onMounted, onUnmounted } from 'vue'; onMounted(() => { window.addEventListener('resize', onResize); }); onUnmounted(() => { window.removeEventListener('resize', onResize); });
import { onMounted } from 'vue'; onMounted(() => { window.addEventListener('resize', onResize); }); // No cleanup on unmount
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| No cleanup of event listeners | No direct DOM ops | 0 | 0 | [X] Bad |
| Cleanup in onUnmounted hook | No direct DOM ops | 0 | 0 | [OK] Good |