โ
๊ณผ์ 1 ๊ตฌํ โ MainTabs.vue, abSlide.vue
์ฝ๋ ์์
๐ MainTabs.vue
๋ด๋ถ ๋ณ๊ฒฝ:
<script>
import TabSlide from "./TabSlide.vue";
export default {
components: { TabSlide },
data() {
return {
currentTab: 0,
renderKey: 0,
mounted: true,
tabs: [
{
label: "๊ตญ์ด",
slides: [
{
img: "https://img.megagong.net/profphoto/gong/gilltoraebi/main_intro.png",
alt: "์ด์ค์ฃผ",
subject: "๊ตญ์ด",
},
{
img: "https://img.megagong.net/profphoto/gong/jhssam1003/main_intro.png",
alt: "์์งํ",
subject: "๊ตญ์ด",
},
],
},
{
label: "์์ด",
slides: [
{
img: "https://img.megagong.net/profphoto/gong/tjenglish08/main_intro.png",
alt: "์กฐํ์ ",
subject: "์์ด",
},
{
img: "https://img.megagong.net/profphoto/gong/megamega2/main_intro.png",
alt: "์ฑ์ ํ",
subject: "์์ด",
},
{
img: "https://img.megagong.net/profphoto/gong/incredvoc/main_intro.png",
alt: "๊ฒฝ์ ์",
subject: "์์ด",
},
{
img: "https://img.megagong.net/profphoto/gong/nojoony1/main_intro.png",
alt: "๋ฐ๋
ธ์ค",
subject: "์์ด",
},
],
},
{
label: "ํ๊ตญ์ฌ",
slides: [
{
img: "https://img.megagong.net/profphoto/gong/gosabu88/main_intro.png",
alt: "๊ณ ์ข
ํ",
subject: "ํ๊ตญ์ฌ",
},
{
img: "https://img.megagong.net/profphoto/gong/vision0911/main_intro.png",
alt: "๋ผ์ํ",
subject: "ํ๊ตญ์ฌ",
},
{
img: "https://img.megagong.net/profphoto/gong/duwo20405/main_intro.png",
alt: "์ต์์ฌ",
subject: "ํ๊ตญ์ฌ",
},
{
img: "https://img.megagong.net/profphoto/gong/jeonhangil/main_intro.png",
alt: "์ ํ๊ธธ",
subject: "ํ๊ตญ์ฌ",
},
],
},
{
label: "ํ์ ํ",
slides: [
{
img: "https://img.megagong.net/profphoto/gong/plower3362/main_intro.png",
alt: "ํฉ์ฒ ๊ณค",
subject: "ํ์ ํ",
},
{
img: "https://img.megagong.net/profphoto/gong/happy0308/main_intro.png",
alt: "์ด์ํ",
subject: "ํ์ ํ",
},
{
img: "https://img.megagong.net/profphoto/gong/shin242/main_intro.png",
alt: "์ ์ฉํ",
subject: "ํ์ ํ",
},
],
},
{
label: "ํ์ ๋ฒ",
slides: [
{
img: "https://img.megagong.net/profphoto/gong/allawyer/main_intro.png",
alt: "์ ํ์ด",
subject: "ํ์ ๋ฒ",
},
{
img: "https://img.megagong.net/profphoto/gong/wjsgywls1/main_intro.png",
alt: "์ ํจ์ง",
subject: "ํ์ ๋ฒ",
},
{
img: "https://img.megagong.net/profphoto/gong/geek2991/main_intro.png",
alt: "์ ์ธ๊ตญ",
subject: "ํ์ ๋ฒ",
},
{
img: "https://img.megagong.net/profphoto/gong/ysw7/main_intro.png",
alt: "์์น์ฐ",
subject: "ํ์ ๋ฒ",
},
],
},
],
};
},
methods: {
changeTab(index) {
this.currentTab = index;
this.mounted = false;
this.$nextTick(() => {
this.renderKey++;
this.mounted = true;
});
},
},
};
</script>
๐ TabSlide.vue <swiper-slide>
๋ด๋ถ ๋ณ๊ฒฝ:
<swiper-slide v-for="(item, i) in slides" :key="i" class="teacher-slide">
<div class="teacher-box">
<img :src="item.img" :alt="item.name" />
<p class="teacher-name">{{ item.name }}</p>
<p class="teacher-subject">{{ item.subject }}</p>
</div>
</swiper-slide>
โ ์คํ์ผ ์ถ๊ฐ
.teacher-subject {
font-size: 13px;
color: #666;
margin-top: 4px;
}
โ ๊ณผ์ 2. ๋ฐ์ํ ์ฒ๋ฆฌ (768px ์ดํ์์ ์ฌ๋ผ์ด๋ ์ ์ค์ด๊ธฐ)
์ด๋ฏธ swiperOption
์ ๋ฐ์ํ์ ๋ฃ์ผ๋ฉด ๋ฉ๋๋ค:
swiperOption: {
slidesPerView: 4,
spaceBetween: 10,
pagination: {
el: ".swiper-pagination",
},
loop: false,
breakpoints: {
1200: { slidesPerView: 4 },
1024: { slidesPerView: 3 },
768: { slidesPerView: 2 },
480: { slidesPerView: 1 },
},
},
โ ์ต์ข ์ ์ฉ ์ ๋ฆฌ
๐ TabSlide.vue
์์ฑ ์์
<template>
<swiper ref="mySwiper" :options="swiperOption" class="swiper-container">
<swiper-slide v-for="(item, i) in slides" :key="i" class="teacher-slide">
<div class="teacher-box">
<img :src="item.img" :alt="item.alt" />
<p class="teacher-name">{{ item.alt }}</p>
<p class="teacher-subject">{{ item.subject }}</p>
</div>
</swiper-slide>
<div class="swiper-pagination" slot="pagination"></div>
</swiper>
</template>
<script>
export default {
props: {
slides: {
type: Array,
required: true,
},
},
data() {
return {
swiperOption: {
slidesPerView: 4,
spaceBetween: 10,
pagination: {
el: ".swiper-pagination",
},
loop: false,
breakpoints: {
1200: { slidesPerView: 4 },
1024: { slidesPerView: 3 },
768: { slidesPerView: 2 },
480: { slidesPerView: 1 },
},
},
};
},
watch: {
slides() {
this.$nextTick(() => {
const swiper = this.$refs.mySwiper?.swiper;
if (swiper) {
swiper.update();
swiper.slideTo(0);
}
});
},
},
};
</script>
<style scoped>
.swiper-container {
width: 100%;
overflow: hidden;
}
.swiper-slide {
/* width: auto !important; */
flex-shrink: 0;
display: flex;
justify-content: center;
}
.teacher-box {
width: 100%;
max-width: 200px;
background: #fff;
border: 1px solid #eee;
border-radius: 8px;
padding: 12px;
text-align: center;
}
.teacher-box:hover {
transform: translateY(-4px);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}
.teacher-box img {
width: 100%;
height: auto;
border-radius: 4px;
margin-bottom: 8px;
}
.teacher-name {
font-size: 14px;
font-weight: 600;
color: #333;
}
.teacher-subject {
font-size: 13px;
color: #666;
margin-top: 4px;
}
</style>
โ ์ด์ ์ด๋ฆ๊ณผ ๊ณผ๋ชฉ์ด ์ฌ๋ผ์ด๋์ ์ ํ์๋๊ณ ,
โ 768px ์ดํ์์ ์ฌ๋ผ์ด๋ ์๊ฐ ์๋์ผ๋ก ์ค์ด๋ค๋ฉฐ ๋ฐ์ํ์ผ๋ก ์์ฐ์ค๋ฝ๊ฒ ์๋ํฉ๋๋ค.
๐ฌ ๋๊ธ
โป ๋ก๊ทธ์ธ ํ ๋๊ธ์ ์์ฑํ ์ ์์ต๋๋ค.