Understanding deep reactivity helps you make your Vue app update correctly when data changes, even inside nested objects or arrays.
Why deep reactivity understanding matters in Vue
import { reactive } from 'vue'; const state = reactive({ user: { name: 'Alice', age: 30 } }); // Changing nested property state.user.age = 31;
reactive() makes an object deeply reactive by default.
Changes inside nested objects or arrays are tracked automatically.
const state = reactive({ count: 0 }); state.count = 1;
const state = reactive({ user: { name: 'Bob' } }); state.user.name = 'Robert';
const state = reactive({ items: [1, 2, 3] }); state.items.push(4);
This Vue component shows a user's age and a button to increase it. Because state is deeply reactive, changing state.user.age updates the displayed age automatically.
<template>
<div>
<p>User age: {{ state.user.age }}</p>
<button @click="increaseAge">Increase Age</button>
</div>
</template>
<script setup>
import { reactive } from 'vue';
const state = reactive({
user: {
age: 25
}
});
function increaseAge() {
state.user.age++;
}
</script>Vue's reactive() tracks nested changes automatically using Proxies. ref() provides the same deep reactivity when the ref holds an object.
Direct index or length mutations on arrays may not trigger updates; prefer using array mutation methods like push(), splice(), etc.
Use Vue DevTools to inspect reactivity and see what changes trigger updates.
Deep reactivity means Vue tracks changes inside nested objects and arrays.
This helps your UI update correctly when nested data changes.
Understanding this avoids bugs and improves app reliability.