Performance: Computed in Composition API
MEDIUM IMPACT
This affects how efficiently reactive data updates trigger UI changes and how often expensive calculations run.
import { ref, computed } from 'vue'; const count = ref(0); const double = computed(() => count.value * 2);
import { ref } from 'vue'; const count = ref(0); function double() { return count.value * 2; }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Using plain functions for derived state | No direct DOM ops | Triggers recalculation on every access | Minimal paint but CPU heavy | [X] Bad |
| Using computed properties | No direct DOM ops | Recalculates only on dependency change | Minimal paint and CPU efficient | [OK] Good |