Vue reactivity

Vue.js는 state-driven UI 모델을 표방하지만, "state를 바꾸면 화면이 알아서 바뀐다"는 문장 자체는 메커니즘을 설명하지 않는다. Reactivity가 바로 그 메커니즘이다 — developer는 state를 바꾸고, Vue는 그 state에 의존하는 rendering 결과를 갱신한다. 이는 event handler마다 DOM node를 직접 찾아 수정하는 방식과 대비되는, state change와 UI update 사이의 추적 관계다. ref vs reactive는 이 reactivity를 사용하는 API 선택 문제이고, 이 페이지는 그 밑에 있는 감지·추적 메커니즘 자체를 다룬다.

감지: state가 바뀌면 무슨 일이 일어나는가

import { ref, reactive } from "vue";

const count = ref(0);
count.value++;

const user = reactive({ nickname: "hissam" });
user.nickname = "vue-user";

추적: Proxy와 getter/setter

flowchart LR
  Event["event/API/user input"] --> State["reactive state changes"]
  State --> Tracking["Vue tracks dependencies"]
  Tracking --> Render["component render updates"]
  Render --> DOM["DOM patch"]

추적이 끊기는 두 지점

절충점

흔한 실패 모드

경계

관련

출처

테스트 질문


  1. 01-1.Vuejs-intro.pdf — "Vue가 state 변화를 감지하고 DOM을 자동으로 갱신한다" ↩︎

  2. 01-1.Vuejs-intro.pdf — ref()/reactive() 정의와 template unwrap 규칙 ↩︎

  3. vue-reactivity-in-depth.md — "In Vue 3, Proxies are used for reactive objects and getter / setters are used for refs." ↩︎

  4. vue-reactivity-in-depth.md — "When you assign or destructure a reactive object's property to a local variable, accessing or assigning to that variable is non-reactive..." ↩︎

  5. 출처 매핑 미확인 — next-tick/batching 주장이 두 인용 소스 어디에서도 확인되지 않는다(01-1.Vuejs-intro.pdf는 그렙 불가, vue-reactivity-in-depth.md는 batch/nextTick 검색 결과 없음). Vue 공식 문서의 lifecycle 또는 nextTick 문서를 새로 읽어 확인할 것. ↩︎