Vue Component Architecture

Vue Component Architecture는 Vue.js의 component-based UI model 하위에서, SFC·Composition API·reactive state·lifecycle로 component 내부를 구성하고 Props·emitted events·Slots로 component 사이의 외부 contract를 노출하는 모델이다. 이 페이지가 답하는 질문은 component 내부 책임과 component 사이의 data/content 흐름을 어떻게 분리하는가다.

Component 캡슐화와 Parent-Child Contract

Contract 방향 책임
Props Parent -> Child Parent가 소유한 data를 read-only input으로 전달한다.
Emitted events Child -> Parent Child interaction을 알리고 parent가 state 변경을 결정한다.
Slots Parent -> Child template Parent가 content 또는 일부 layout을 주입한다.

SFC 내부 구성: Option API와 Composition API

Component 사이의 public contract

Ownership과 contract가 설계의 핵심인 이유

Component reuse의 핵심은 파일을 작게 나누는 것이 아니라 소유권과 contract를 명시하는 것이라고 볼 수 있다. State ownership은 변경을 승인하는 component에 두고, 하위 component는 Props로 읽고 event로 의도를 알린다. Markup/content variation이 문제라면 data Props를 늘리기보다 Slot으로 composition boundary를 제공하는 편이 낫다. 이 구분을 유지하면 component API가 "data input, behavior output, content input"으로 읽혀 변경 영향을 추적하기 쉬워진다는 관점에서 유용하다.

다른 개념과의 관계

Component architecture는 Vue Reactivity 위에서 성립한다 — Props와 local state 변경이 rendering에 반영되는 것은 reactivity 메커니즘 덕분이다. Template에서 binding과 event listener를 선언할 때는 Vue Directives를 사용한다. Vue Advanced Components는 이 Props/Emit/Slots 선택 절차를 실제 component 설계에 적용하는 pattern이고, Vue Router는 route component를 이 architecture 위의 view hierarchy에 배치한다.

경계

메커니즘

<!-- ItemButton.vue -->
<script setup>
const props = defineProps({ title: String })
const emit = defineEmits(['action'])
</script>

<template>
  <button @click="emit('action', props.title)">
    <slot>{{ title }}</slot>
  </button>
</template>
<!-- Parent.vue -->
<ItemButton title="저장" @action="handleSave">
  <strong>변경 저장</strong>
</ItemButton>
flowchart LR
  Parent[Parent owner]
  Child[Child component]
  Content[Parent content]
  Parent -- "Props: read-only data" --> Child
  Child -. "Emit: interaction + payload" .-> Parent
  Content -- "Slot: markup/content" --> Child

절충점

관련

출처

테스트 질문


  1. vue-component-basics.md, vue-component-props.md — "Components allow us to split the UI into independent and reusable pieces"; props의 one-way data flow와 mutation 경고, defineProps()가 <script setup> compile-time macro라는 설명 ↩︎ ↩︎ ↩︎

  2. 03.Vuejs-Component.pdf — SFC 구조, Option API/Composition API 비교, setup() 실행 시점 ↩︎ ↩︎ ↩︎ ↩︎

  3. 04.Vuejs-Component심화.pdf — Props를 read-only data로, event를 defineEmits()로, Slot을 named/scoped content insertion point로 설명 ↩︎ ↩︎ ↩︎