Performance: Computed with getter and setter
MEDIUM IMPACT
This affects how reactive data updates trigger DOM updates and re-renders in Vue components.
const fullName = computed({ get() { return firstName.value + ' ' + lastName.value; }, set(value) { const parts = value.split(' '); firstName.value = parts[0]; lastName.value = parts.slice(1).join(' ') || ''; } });
const fullName = computed(() => firstName.value + ' ' + lastName.value); // Updating fullName directly is not possible, so manual watchers or methods are used to sync changes
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Computed with getter only and manual sync | Multiple reactive triggers | Multiple reflows per update | Higher paint cost due to redundant renders | [X] Bad |
| Computed with getter and setter | Single reactive trigger per update | Single reflow per update | Lower paint cost due to optimized renders | [OK] Good |