써치킴의 우당탕탕 개발 블로그

[Vue.js][Ch4][영화검색 사이트] 영화 상세 페이지 정리 본문

완벽하게 Vue.js

[Vue.js][Ch4][영화검색 사이트] 영화 상세 페이지 정리

써치킴 2022. 4. 25. 21:49

Movie.vue

<template>
  <div class="container">
    <template v-if="loading"> <!-- 로딩중이면 skeleton 출력 -->
      <div class="skeletons">
        <div class="skeleton poster"></div>
          <div class="specs">
            <div class="skeleton title"></div>
            <div class="skeleton spec"></div>
            <div class="skeleton plot"></div>
            <div class="skeleton etc"></div>
            <div class="skeleton etc"></div>
            <div class="skeleton etc"></div>
          </div>
      </div>
      <Loader  
      :size="3"
      :zIndex="9"
      fixed />   <!-- 정중앙에 로딩애니메이션 동작 -->
    </template>
    <div
      v-else
      class="movie-details">    <!-- 로딩중이지 않으면 상세정보 출력 -->
      <div
        :style="{ backgroundImage: `url(${theMovie.Poster})` }" 
        class="poster"></div>
      <div class="specs">
        <div class="title">
          {{ theMovie.Title }}
        </div>
        <div class="labels">
          <span>{{ theMovie.Released }}</span>
          <span>{{ theMovie.Runtime }}</span>
          <span>{{ theMovie.Country }}</span>
        </div>
        <div class="plot">
          {{ theMovie.Plot }}
        </div>
        <div class="ratings">
          <h3>Ratings</h3>
        </div>
        <div>
          <h3>Actors</h3>
          {{ theMovie.Actors }}
        </div>
        <div>
          <h3>Director</h3>
          {{ theMovie.Director }}
        </div>
        <div>
          <h3>Production</h3>
          {{ theMovie.Production }}
        </div>
        <div>
          <h3>Genre</h3>
          {{ theMovie.Genre }}
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import Loader from '~/components/Loader'

export default {
  components: {
    Loader
  },
  computed: {
    theMovie() {
      return this.$store.state.movie.theMovie;
    },
    loading() {
      return this.$store.state.movie.loading;
    }
  },
  created() {      // Movie 컴포넌트가 실행되면
    console.log(this.$route);     // 현재 페이지 주소 정보를 가져옴
    this.$store.dispatch('movie/searchMovieWithId', {
      // ex) movie/tt1234545
      id: this.$route.params.id   // 주소 부분의 파라미터에서 omdbID를 가져옴
    });
  }
}
</script>

<style lang="scss" scoped>
@import "~/scss/main";    /* 부트스트랩을 사용할 수 있게 import */

.container {
  padding-top: 40px;
}
.skeletons {
  display: flex;
  .poster {
    flex-shrink: 0;     // 감소 너비를 사용하지 않겠다.
    width: 500px;
    height: 500px * 3 / 2;
    margin-right: 70px;
  }
  .specs {
    flex-grow: 1;       // 증가 너비를 최대한 많이 사용하겠다.
  }
  .skeleton {
    border-radius: 10px;
    background-color: $gray-200;
    &.title {
      width: 80%;
      height: 70px;
    }
    &.spec {
      width: 60%;
      height: 30px;
      margin-top: 20px;
    }
    &.plot {
      width: 100%;
      height: 250px;
      margin-top: 20px;
    }
    &.etc {
      width: 50%;
      height: 50px;
      margin-top: 20px;
    }
  }
}

.movie-details {
  display: flex;
  color: $gray-600;
  .poster {
    width: 500px;
    height: 500px * 3/2;
    margin-right: 70px;
    border-radius: 10px;
    background-color: $gray-200;
    background-size: cover;
    background-position: center;
    position: relative;
    flex-shrink: 0;
  }
  .specs {
    flex-grow: 1;
    .title {
      color: $black;
      font-family: "Oswald", sans-serif;
      font-size: 70px;
      line-height: 1;
      margin-bottom: 30px;
    }
    .labels {
      color: $primary;
      span {
        &::after {    // 가상요소 생성
          content: "\00b7";   // 가운데점
          margin: 0 6px;
        }
        &:last-child::after {
          display: none;
        }
      }
    }
    .plot {
      margin-top: 20px;
    }
    .ratings {
      
    }
    h3 {
      margin: 24px 0 6px;
      color: $black;
      font-family: "Oswald", sans-serif;
      font-size: 20px;
    }
  }
}
</style>

출력

Comments