프로젝트/영화 검색 (Vue)
Vue 프로젝트 영화 아이템 - 기본 출력
IT Blue
2021. 8. 6. 06:31
Vue 프로젝트 영화 아이템 - 기본 출력
1. /src/components/MovieItem.vue 수정
- 영화 포스터, 년도, 제목 출력
<template>
<div
:style="{ backgroundImage: `url(${movie.Poster})` }"
class="movie">
<div class="info">
<div class="year">
{{ movie.Year }}
</div>
<div class="title">
{{ movie.Title }}
</div>
</div>
</div>
</template>
<script>
export default {
props: {
movie: {
type: Object,
default: () => ({})
}
}
}
</script>
<style lang="scss" scoped>
@import "~/scss/main";
.movie {
$width: 200px;
width: $width;
height: $width * 3 / 2;
margin: 10px;
background-repeat: 4px;
background-color: $gray-400;
background-size: cover;
overflow: hidden;
position: relative;
.info {
background-color: rgba($black, .3);
width: 100%;
padding: 14px;
font-size: 14px;
text-align: center;
position: absolute;
left: 0;
bottom: 0;
}
}
</style>
2. /src/components/MovieList.vue 수정
- MovieItem 수평 정렬
<template>
<div class="container">
<div class="inner">
... 생략
<div class="movies">
<MovieItem
v-for="movie in movies"
:key="movie.imdbID"
:movie="movie" />
</div>
</div>
</div>
</template>
<script>
import MovieItem from '~/components/MovieItem'
export default {
components: {
MovieItem
},
computed: {
... 생략
}
}
</script>
<style lang="scss" scoped>
.container {
.movies {
display: flex;
flex-wrap: wrap;
justify-content: center;
}
}
</style>
결과