Performance: Route parameters with useRoute
MEDIUM IMPACT
This affects how quickly the app can read and react to URL changes, impacting interaction responsiveness and rendering updates.
import { useRoute } from 'vue-router'; import { ref, watch } from 'vue'; export default { setup() { const route = useRoute(); const userId = ref(route.params.userId); watch(() => route.params.userId, (newId) => { userId.value = newId; }); return { userId }; } }
import { useRoute } from 'vue-router'; export default { setup() { const route = useRoute(); const userId = route.params.userId; // Using userId directly without watching route changes return { userId }; } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct read without watch | Minimal DOM ops | 0 reflows triggered by param read | Low paint cost but stale UI | [X] Bad |
| Reactive watch on route params | Minimal DOM ops | Reflow only on param change | Paint only on param change | [OK] Good |