Skip to Content
Vue 학습
book

Vue 학습

by Maya Shavin
May 2025
Beginner to intermediate
350 pages
5h 20m
Korean
O'Reilly Media, Inc.
Content preview from Vue 학습

3장. 구성 요소 구성하기

이 작품은 AI를 사용하여 번역되었습니다. 여러분의 피드백과 의견을 환영합니다: translation-feedback@oreilly.com

이전 장에서는 Vue의 기본 사항과 Options API를 사용하여 일반적인 지시문을 사용하여 Vue 컴포넌트를 작성하는 방법을 배웠습니다. 이제 다음 단계인 반응성과 후크를 사용하여 더 복잡한 Vue 컴포넌트를 작성할 준비가 되었습니다.

이 장에서는 Vue 단일 파일 컴포넌트(SFC) 표준, 컴포넌트 수명 주기 후크, 계산된 속성, 감시자, 메서드 및 참조와 같은 기타 고급 반응형 기능에 대해 소개합니다. 또한 슬롯을 사용하여 컴포넌트의 여러 부분을 동적으로 렌더링하는 동시에 스타일로 컴포넌트의 구조를 유지하는 방법도 배웁니다. 이 장이 끝나면 애플리케이션에서 복잡한 Vue 컴포넌트를 작성할 수 있게 됩니다.

Vue 단일 파일 컴포넌트 구조

Vue는 .vue 확장자로 표시되는 새로운 파일 형식 표준인 Vue SFC를 도입했습니다. SFC를 사용하면 동일한 파일에 HTML 템플릿 코드, JavaScript 로직 및 컴포넌트에 대한 CSS 스타일을 각각 전용 코드 섹션에 작성할 수 있습니다. Vue SFC에는 세 가지 필수 코드 섹션 이 포함되어 있습니다:

템플릿

이 HTML 코드 블록은 컴포넌트의 UI 보기를 렌더링합니다. 컴포넌트당 최상위 요소 에 한 번만 표시되어야 합니다.

스크립트

이 JavaScript 코드 블록은 컴포넌트의 주요 로직을 포함하며 컴포넌트 파일당 최대 한 번만 나타납니다.

스타일

이 CSS 코드 블록에는 컴포넌트의 스타일이 포함되어 있습니다. 선택 사항이며 컴포넌트 파일당 필요한 횟수만큼 표시할 수 있습니다.

예제 3-1은 MyFirstComponent 이라는 이름의 Vue 컴포넌트에 대한 SFC 파일 구조의 예입니다.

예제 3-1. MyFirstComponent 컴포넌트의 SFC 구조
<template>
 <h2 class="heading">I am a a Vue component</h2>
</template>
<script lang="ts">
export default {
 name: 'MyFistComponent',
};
</script>
<style>
.heading {
  font-size: 16px;
}
</style>

그림 3-1 과 같이 비 SFC 컴포넌트 코드를 SFC로 리팩터링할 수도 있습니다.

Example of a Vue component created with single file component concept
그림 3-1. 컴포넌트를 비-SFC 형식에서 SFC 형식으로 리팩터링하기

그림 3-1에서 볼 수 있듯이 다음과 같은 리팩터링을 수행합니다:

  • template 필드의 문자열 값으로 표시된 HTML 코드를 단일 파일 컴포넌트의 <template> 섹션으로 이동합니다.

  • 나머지 MyFirstComponent 로직은 export default {} 객체의 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

MLOps 도입 가이드

MLOps 도입 가이드

데이터이쿠
DevOps를 위한 Python

DevOps를 위한 Python

Noah Gift, Kennedy Behrman, Alfredo Deza, Grig Gheorghiu

Publisher Resources

ISBN: 9798341654730