Performance: Reactive objects with reactive
This affects how Vue tracks changes in objects and updates the DOM efficiently.
const state = reactive({ user: { name: 'Alice', age: 30 } }); // Use Vue's reactive system properly; mutations are tracked efficiently state.user.name = 'Bob';
const state = ref({ user: { name: 'Alice', age: 30 } }); // Directly mutating nested properties without reactivity helpers state.value.user.name = 'Bob';
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Direct nested mutation without optimization | Multiple DOM updates | Multiple reflows | High paint cost | [X] Bad |
| Reactive object with minimal nested changes | Single DOM update | Single reflow | Low paint cost | [OK] Good |
reactive function in Vue do?reactivereactive function wraps an object so Vue can track its property changes.reactive({ count: 0 }).import { reactive } from 'vue'
const state = reactive({ count: 1 })
state.count = 5
console.log(state.count)state.count = 5 updates the reactive property value.state.count after update outputs the new value 5.import { reactive } from 'vue'
const state = reactive({ count: 0 })
state = { count: 5 }state is declared with const, so it cannot be reassigned.Pass the test and this pattern moves unknown