Vue - 학습 기록 앱 만들기 3 : Base Button Component

2023. 8. 5. 16:45·📘 Frontend/Vue

Base Button Components

학습 기록 앱에 쓰일 기본 버튼 Component를 추가해보겠습니다.


props중 type 프로퍼티는,

버튼의 타입을 받아서 타입마다 다른 CSS를 적용할 수 있게 Style을 해두었습니다. (ex: 마우스를 올릴 시 다른 CSS 적용)

mode 프로퍼티는 CSS의 Class 명을 받아서 mode에 바인딩 해줍니다.

그리고, 버튼에 들어갈 컨텐츠는 당연히 외부에서 받아야 하므로 slot으로 받습니다.


BaseButton.vue

<template>  
  <button :type="type" :class="mode">  
    <slot></slot>  
  </button>  
</template>  

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

<style scoped>  
button {  
  padding: 0.75rem 1.5rem;  
  font-family: inherit;  
  background-color: #3a0061;  
  border: 1px solid #3a0061;  
  color: white;  
  cursor: pointer;  
}  

button:hover,  
button:active {  
  background-color: #270041;  
  border-color: #270041;  
}  

.flat {  
  background-color: transparent;  
  color: #3a0061;  
  border: none;  
}  

.flat:hover,  
.flat:active {  
  background-color: #edd2ff;  
}  
</style>

그리고, 이 기본 버튼도 다른 컴포넌트들에서 계속 사용할 것이기 떄문에 전역 컴포넌트로 등록해줍니다.

main.js

import { createApp } from 'vue';  

import App from './App.vue';  
import BaseCard from './components/UI/BaseCard.vue';  
import BaseButton from "@/components/UI/BaseButton";  

const app = createApp(App)  

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

app.mount('#app');

그리고 기존 LearningResource 컴포넌트에서도 버튼을 사용하고 있으니, 여기서도 BaseButton 태그로 변경해줍니다.

LearningResource.vue

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

이제 버튼의 UI가 변경되었습니다.

img

버튼의 테두리가 마음에 안든다면 base-button을 호출하는 속성으로 mode="flat"을 주면 해결됩니다.

저작자표시

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

Vue - 학습 기록 앱 만들기 5 : Input Form 구현  (0) 2023.08.05
Vue - 학습 기록 앱 만들기 4 : 탭 간 전환 구현  (0) 2023.08.05
Vue - 학습 기록 앱 만들기 2 : UI/Layout Components  (0) 2023.08.05
Vue - 학습 기록 앱 만들기 1 : Resources & Styling  (0) 2023.08.05
Vue - 빠른 학습을 위한 기록 잠정 중단  (0) 2023.08.05
'📘 Frontend/Vue' 카테고리의 다른 글
  • Vue - 학습 기록 앱 만들기 5 : Input Form 구현
  • Vue - 학습 기록 앱 만들기 4 : 탭 간 전환 구현
  • Vue - 학습 기록 앱 만들기 2 : UI/Layout Components
  • Vue - 학습 기록 앱 만들기 1 : Resources & Styling
신건우
신건우
조용한 개발자
  • 신건우
    우주먼지
    신건우
  • 전체
    오늘
    어제
    • 분류 전체보기 (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
    • 공지사항

    • 인기 글

    • 태그

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

    • 최근 글

    • hELLO· Designed By정상우.v4.10.0
    신건우
    Vue - 학습 기록 앱 만들기 3 : Base Button Component
    상단으로

    티스토리툴바