Performance: Computed vs method performance
This affects how fast Vue updates and renders reactive data on the page during user interaction.
export default { data() { return { count: 0 }; }, computed: { doubled() { return this.count * 2; } } }
export default { data() { return { count: 0 }; }, methods: { doubled() { return this.count * 2; } } }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Method for reactive value | No extra DOM nodes | Multiple recalculations trigger more JS work | Normal paint cost | [X] Bad |
| Computed property for reactive value | No extra DOM nodes | Recalculates only on dependency change | Normal paint cost | [OK] Good |
fullName in a Vue 3 component using the Composition API?computed function with a getter function.computed(() => ...). Options B and C use Options API syntax, and D is just a plain function without caching.setup() {
const count = ref(0);
const doubleCount = computed(() => {
console.log('Computed called');
return count.value * 2;
});
function increment() {
count.value++;
console.log('Method called:', doubleCount.value);
}
return { count, doubleCount, increment };
}count.value changes.filteredList() which runs on every render, causing lag with large data. How can you optimize this using computed properties? Consider that the list and search term are reactive refs.Pass the test and this pattern moves unknown