Roadmap › Vue.js 3 (with Pinia, Vue Router & Nuxt basics) › Module: Reactivity
Lessons in this course (17)
6. How Vue 3 reactivity works
Intermediate★ Must knowLesson 6 of 17
reactive()wraps an object in a Proxy: thegettrap tracks which running effect (component render, computed, watcher) read the property; thesettrap triggers those effects.ref()is an object with a getter/setter on.valuedoing the same tracking.- Effects re-run → component re-render is scheduled → batched → DOM patched in the next tick (
await nextTick()to read updated DOM). - Vue 2 used
Object.defineProperty, so it couldn't detect added/deleted properties or array index assignment — you neededVue.set/this.$set. Vue 3's Proxies detect all of these.
ts
const state = reactive({ user: { name: "Asha" } });
state.user.email = "a@x.com"; // reactive in Vue 3 (needed Vue.set in Vue 2)
const arr = reactive([1, 2, 3]);
arr[0] = 99; // reactive in Vue 3