Vue - 학습 기록 앱 만들기 2 : UI/Layout Components

2023. 8. 5. 16:20·📘 Frontend/Vue
목차
  1. UI Components
  2. Layout Components

UI Components

이제 UI 컴포넌트들 만들어보겠습니다.

BaseCard라는 컴포넌트를 만들고 scoped 스타일링을 적용해서 원하는 HTML 요소에 slot을 달면 적용됩니다.


BaseCard.vue

<template>  
  <header>  
    <h1>{{ title }}</h1>  
  </header>  
</template>  

<script>  
export default {  
  props: ['title'],  
}  
</script>  

<style scoped>  
header {  
  width: 100%;  
  height: 5rem;  
  background-color: #640032;  
  display: flex;  
  justify-content: center;  
  align-items: center;  
}  

header h1 {  
  color: white;  
  margin: 0;  
}  
</style>

그리고 전에 작성한 LearningResource.vue 파일의 div 태그를 base-card 태그로 바꿔주면 Card의 CSS가 적용됩니다.

<template>  
  <li>  
    <base-card>  
      <header>  
        <h3>{{ title }}</h3>  
        <button>Delete</button>  
      </header>  
      <p>{{ description }}</p>  
      <nav>  
        <a :href="link">View Resource</a>  
      </nav>  
    </base-card>  
  </li>  
</template>  

<script>  
export default {  
  props: ['title', 'description', 'link'],  

}  
</script>

그리고, 이 UI 컴포넌트는 LearningResource 컴포넌트 뿐만 아니라 다른 컴포넌트에서도 사용할 것이므로,

Local 컴포넌트가 아닌 Global 컴포넌트로 등록 할겁니다.

main.js

import { createApp } from 'vue';  

import App from './App.vue';  
import BaseCard from './components/UI/BaseCard.vue';  

const app = createApp(App)  

app.component('base-card', BaseCard);  

app.mount('#app');

Card UI가 적용된 모습

img


Layout Components

이제 Layout Component인 Header 컴포넌트를 만들어 보겠습니다.

저번에 말했듯이 App.vue에는 어떠한 마크업도 들어가게 하지 않기 위해 레이아웃의 Header도 별도의 Wrapper 컴포넌트로 만듭니다.


Title에 해당하는 데이터를 BaseHeader에서 props로 가져와서 간단하게 title값만 바인딩 하였고,

원래 App.vue에 들어갈 title을 BaseHeader 컴포넌트로 대체하였습니다.


BaseHeader.vue

<template>  
  <header>  
    <h1>{{ title }}</h1>  
  </header>  
</template>  

<script>  
export default {  
  props: ['title'],  
}  
</script>  

<style scoped>  
header {  
  width: 100%;  
  height: 5rem;  
  background-color: #640032;  
  display: flex;  
  justify-content: center;  
  align-items: center;  
}  

header h1 {  
  color: white;  
  margin: 0;  
}  
</style>

App.vue

<template>  
  <base-header title="학습 기록"></base-header>  
  <stored-resources :resources="storedResources"></stored-resources>  
</template>  

<script>  
import StoredResources from "@/components/Learing-Resources/StoredResources";  
import BaseHeader from "@/components/Layouts/BaseHeader";  

export default {  
  components: { StoredResources, BaseHeader },  

  data() {  
    return {  
      storedResources: [  
        {  
          id: 'official-guide',  
          title: 'Official Guide',  
          description: 'The Official Vue.js Documentation',  
          link: 'https://vuejs.org'  
        },  
        {  
          id: 'google',  
          title: 'Google',  
          description: 'The Official Google Documentation',  
          link: 'https://google.org'  
        },  
      ]  
    };  
  },  
}  
</script>

결과물

img

저작자표시 (새창열림)

'📘 Frontend > Vue' 카테고리의 다른 글

Vue - 학습 기록 앱 만들기 4 : 탭 간 전환 구현  (0) 2023.08.05
Vue - 학습 기록 앱 만들기 3 : Base Button Component  (0) 2023.08.05
Vue - 학습 기록 앱 만들기 1 : Resources & Styling  (0) 2023.08.05
Vue - 빠른 학습을 위한 기록 잠정 중단  (0) 2023.08.05
Vue - Component Custom Event ($emit())  (0) 2023.08.03
  1. UI Components
  2. Layout Components
'📘 Frontend/Vue' 카테고리의 다른 글
  • Vue - 학습 기록 앱 만들기 4 : 탭 간 전환 구현
  • Vue - 학습 기록 앱 만들기 3 : Base Button Component
  • Vue - 학습 기록 앱 만들기 1 : Resources & Styling
  • Vue - 빠른 학습을 위한 기록 잠정 중단
신건우
신건우
조용한 개발자
  • 신건우
    우주먼지
    신건우
  • 전체
    오늘
    어제
    • 분류 전체보기 (422)
      • 📘 Frontend (71)
        • Markup (1)
        • Style Sheet (2)
        • Dart (8)
        • Javascript (12)
        • TypeScript (1)
        • Vue (36)
        • React (2)
        • Flutter (9)
      • 📘 Backend (143)
        • Java (34)
        • Concurrency (19)
        • Reflection (1)
        • Kotlin (29)
        • Python (1)
        • Spring (42)
        • Spring Cloud (5)
        • Message Broker (5)
        • Streaming (2)
        • 기능 개발 (5)
      • 💻 Server (6)
        • Linux (6)
      • ❌ Error Handling (11)
      • 📦 Database (62)
        • SQL (31)
        • NoSQL (2)
        • JPQL (9)
        • QueryDSL (12)
        • Basic (4)
        • Firebase (4)
      • ⚙️ Ops (57)
        • CS (6)
        • AWS (9)
        • Docker (8)
        • Kubernetes (13)
        • MSA (1)
        • CI & CD (20)
      • 📚 Data Architect (48)
        • Data Structure (10)
        • Algorithm (8)
        • Programmers (17)
        • BaekJoon (5)
        • CodeUp (4)
        • Design Pattern (4)
        • AI (0)
      • ⚒️ Management & Tool (8)
        • Git (7)
        • IntelliJ (1)
      • 📄 Document (10)
        • Project 설계 (6)
        • Server Migration (3)
      • 📄 책읽기 (2)
        • 시작하세요! 도커 & 쿠버네티스 (2)
      • 🎮 Game (4)
        • Stardew Vally (1)
        • Path of Exile (3)
  • 블로그 메뉴

    • 링크

      • Github
    • 공지사항

    • 인기 글

    • 태그

      Lock #Thread #Concurrency
      React #Markdown
      GStreamer #Pipeline
    • 최근 댓글

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    신건우
    Vue - 학습 기록 앱 만들기 2 : UI/Layout Components
    상단으로

    티스토리툴바

    단축키

    내 블로그

    내 블로그 - 관리자 홈 전환
    Q
    Q
    새 글 쓰기
    W
    W

    블로그 게시글

    글 수정 (권한 있는 경우)
    E
    E
    댓글 영역으로 이동
    C
    C

    모든 영역

    이 페이지의 URL 복사
    S
    S
    맨 위로 이동
    T
    T
    티스토리 홈 이동
    H
    H
    단축키 안내
    Shift + /
    ⇧ + /

    * 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.