89. Adding Tabs

npm create vue@latest


이 강의에서는 모달 내의 탭을 기능적으로 만들 것입니다.
애플리케이션이 서서히 완성되고 있습니다.
모달은 기능적입니다.
다음 단계는 내용에 로직을 추가하는 것입니다.
모달 내부에는 로그인과 등록 양식이라는 두 개의 양식이 있습니다.
두 양식이 동시에 나타나서는 안 됩니다.
양식 위에는 두 개의 버튼이 있습니다.
사용자가 양식 간에 전환할 수 있도록 이 버튼들을 기능적으로 만들 것입니다.
이 기능은 탭으로 알려져 있습니다.
시작해봅시다.
편집기에서 인증 컴포넌트 파일을 엽니다.
첫 번째 단계는 탭의 현재 상태를 다루는 것입니다.
어떤 양식을 사용자에게 보여줄까요?
우리는 로그인 양식을 기본 양식으로 설정할 것입니다.
어떤 양식을 보여줄지 추적해야 합니다.
우리는 두 가지 옵션을 가지고 있습니다.
이 정보를 스토어에 저장하거나 컴포넌트 데이터로 저장할 수 있습니다.
우리는 컴포넌트 데이터로 저장할 것입니다.
이 정보는 전역적으로 사용할 필요가 없습니다.
데이터를 생성할 때마다, 그 데이터가 전역적으로 사용될 필요가 있는지 스스로에게 물어봐야 합니다.
만약 그렇다면, 스토어에 저장하는 것이 좋은 방법입니다.
그렇지 않다면, 컴포넌트 데이터로 저장하는 것으로 충분합니다.
불필요한 데이터로 스토어를 혼잡하게 만들고 싶지는 않을 것입니다.
스크립트로 스크롤 내리세요.
데이터 메서드를 정의할 것입니다.
객체 내부에서, 'Tab'이라는 속성을 추가할 것입니다.
그 값은 다음과 같을 것입니다. 로그인.
값이 로그인이면 로그인 양식을 보여줄 것입니다.
값이 등록이면 등록 양식을 보여줄 것입니다.

이 데이터를 사용하여 템플릿에서 양식의 가시성을 전환합시다.
탭이라고 적힌 주석을 찾으세요.
이 주석 아래에는 탭의 링크가 있습니다.
두 앵커 요소에 Prevent Modifier가 있는 클릭 이벤트 리스너를 추가할 것입니다.
로그인 링크의 경우, 탭 속성을 로그인으로 설정합니다.
다음으로, 등록 링크에 대해서는 탭 속성을 등록으로 설정합니다.
이 속성을 업데이트함으로써 속성 변경 후 탭을 전환할 수 있어야 합니다.
해야 할 마지막 일은 로그인 링크의 탭 외관을 변경하는 것입니다.
Hover Text White, Text White, BG Blue 600이라는 세 개의 클래스가 있습니다.
이 클래스들은 링크의 배경색을 파란색으로, 텍스트 색상을 하얀색으로 변경합니다.
이 클래스들은 탭이 활성화되었을 때만 적용되어야 합니다.
다른 클래스 속성을 바인딩할 것입니다.
이 속성의 값은 객체가 될 것입니다.
앞서 언급한 세 클래스를 이 객체의 속성으로 자르고 붙일 것입니다.
조건에 대해서는 탭 속성이 로그인과 같은지 확인합니다.
사용자가 로그인 양식을 보고 있으면 이 클래스들이 적용됩니다.
또 다른 클래스 세트를 추가할 것입니다.
사용자가 등록 양식을 보고 있으면 적용될 클래스는 Hover Text Blue 600입니다.
이 클래스는 요소 위로 마우스를 올렸을 때 텍스트 색상을 파란색으로 변경합니다.
요소와 상호 작용할 수 있음을 사용자에게 알리기 위해 이 클래스를 추가하는 것입니다.
이 클래스의 조건은 다음과 같습니다:

탭 === 등록.

로그인 탭은 이로써 마무리됩니다.
등록 탭 작업을 시작합시다.
이전과 비슷합니다.
클래스 속성을 복사하여 바인딩합니다.
등록 탭 링크에 붙여넣고, 조건들을 뒤집습니다.
이 수정으로 우리가 원하는 것의 반대를 얻게 됩니다.
마지막 단계가 남았습니다.
순서 없는 리스트 요소 아래에 있는 양식의 가시성을 전환해야 합니다.
두 개의 양식 요소가 있습니다.
첫 번째 양식은 로그인 양식이고, 다른 양식은 등록 양식입니다.
양식의 모습을 전환하기 위해 조건부 지시문을 사용할 것입니다.
첫 번째 양식에 V show 지시문을 추가합니다.
조건은 다음과 같습니다:

탭 === 로그인.

마지막으로, 두 번째 양식에도 V show 지시문을 추가해야 합니다.

조건은 다음과 같습니다:

탭 === 등록.

이제 끝났습니다.
변경 사항을 저장하고 페이지를 새로고침하세요.
모달을 열면 로그인 양식이 나타나고, 등록 양식은 사라집니다.
링크 위에는 적절한 클래스가 적용되어야 합니다.
로그인 양식이 표시되므로 로그인 링크에는 파란색 배경색이 있어야 합니다.
등록 링크를 클릭하면 로그인 양식은 사라지고 등록 양식이 나타납니다.
탭도 변경됩니다.
멋지군요. 작동하는 것을 확인한 후에는 다음 단계로 넘어갈 수 있습니다.
다음 섹션에서는 양식 유효성 검사를 추가할 것입니다.

src/App.vue
<script setup lang="ts">
import AppHeader from '@/components/AppHeader.vue'
import AppAuth from '@/components/AppAuth.vue'
</script>

<template>
  <AppHeader />
  <!-- Introduction -->
  <section class="mb-8 py-20 text-white text-center relative">
    <div
      class="absolute inset-0 w-full h-full bg-contain introduction-bg"
      style="background-image: url('assets/img/header.png')"
    ></div>
    <div class="container mx-auto">
      <div class="text-white main-header-content">
        <h1 class="font-bold text-5xl mb-5">Listen to Great Music!</h1>
        <p class="w-full md:w-8/12 mx-auto">
          Lorem ipsum dolor sit amet, consectetur adipiscing elit. Phasellus et dolor mollis, congue
          augue non, venenatis elit. Nunc justo eros, suscipit ac aliquet imperdiet, venenatis et
          sapien. Duis sed magna pulvinar, fringilla lorem eget, ullamcorper urna.
        </p>
      </div>
    </div>

    <img
      class="relative block mx-auto mt-5 -mb-20 w-auto max-w-full"
      src="/assets/img/introduction-music.png"
    />
  </section>

  <!-- Main Content -->
  <section class="container mx-auto">
    <div class="bg-white rounded border border-gray-200 relative flex flex-col">
      <div class="px-6 pt-6 pb-5 font-bold border-b border-gray-200">
        <span class="card-title">Songs</span>
        <!-- Icon -->
        <i class="fa fa-headphones-alt float-right text-green-400 text-xl"></i>
      </div>
      <!-- Playlist -->
      <ol id="playlist">
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
        <li
          class="flex justify-between items-center p-3 pl-6 cursor-pointer transition duration-300 hover:bg-gray-50"
        >
          <div>
            <a href="#" class="font-bold block text-gray-600">Song Title</a>
            <span class="text-gray-500 text-sm">Artist Name</span>
          </div>

          <div class="text-gray-600 text-lg">
            <span class="comments">
              <i class="fa fa-comments text-gray-600"></i>
              15
            </span>
          </div>
        </li>
      </ol>
      <!-- .. end Playlist -->
    </div>
  </section>

  <!-- Player -->
  <div class="fixed bottom-0 left-0 bg-white px-4 py-2 w-full">
    <!-- Track Info -->
    <div class="text-center">
      <span class="song-title font-bold">Song Title</span> by
      <span class="song-artist">Artist</span>
    </div>
    <div class="flex flex-nowrap gap-4 items-center">
      <!-- Play/Pause Button -->
      <button type="button">
        <i class="fa fa-play text-gray-500 text-xl"></i>
      </button>
      <!-- Current Position -->
      <div class="player-currenttime">00:00</div>
      <!-- Scrub Container  -->
      <div class="w-full h-2 rounded bg-gray-200 relative cursor-pointer">
        <!-- Player Ball -->
        <span class="absolute -top-2.5 -ml-2.5 text-gray-800 text-lg" style="left: 50%">
          <i class="fas fa-circle"></i>
        </span>
        <!-- Player Progress Bar-->
        <span
          class="block h-2 rounded bg-gradient-to-r from-green-500 to-green-400"
          style="width: 50%"
        ></span>
      </div>
      <!-- Duration -->
      <div class="player-duration">03:06</div>
    </div>
  </div>

  <AppAuth />
</template>