OPEN HYPER STEP
← 목록으로 (Vue 3)
VUE · 33 / 34
vue
CHAPTER 33 / 34
읽기 약 2
FUNCTION

Vue 3 실전: 캐러셀 슬라이더


핵심 개념

ref와 setInterval로 자동 재생 캐러셀을 구현합니다. 이전/다음 버튼과 인디케이터로 수동 제어도 가능합니다. 슬라이더를 지우며 콘텐츠 전환이 어떻게 멈추는지 확인하십시오.

코드 분석
VUE📋 코드 (34줄)


const{createApp,ref,onMounted,onUnmounted}=Vue;
createApp({
  setup(){
    const slides=[
      {title:'HTML5',desc:'웹의 뼈대를 해체하라',color:'#ff6b35'},
      {title:'CSS3',desc:'스타일을 해부하라',color:'#3b82f6'},
      {title:'JavaScript',desc:'로직을 분해하라',color:'#f59e0b'},
      {title:'Vue 3',desc:'컴포넌트를 해체하라',color:'#22c55e'},
    ];
    const curr=ref(0);let timer;
    const next=()=>curr.value=(curr.value+1)%slides.length;
    const prev=()=>curr.value=(curr.value-1+slides.length)%slides.length;
    onMounted(()=>timer=setInterval(next,3000));
    onUnmounted(()=>clearInterval(timer));
    return{slides,curr,next,prev};
  },
  template:`<div>
    <div style='position:relative;overflow:hidden;height:100px;background:#0a0a0a;margin-bottom:8px;display:flex;align-items:center;justify-content:center;'>
      <div :style='{color:slides[curr].color}' style='text-align:center;'>
        <div style='font-size:20px;font-weight:bold;letter-spacing:0.05em;'>{{slides[curr].title}}</div>
        <div style='font-size:11px;color:#555;margin-top:4px;'>{{slides[curr].desc}}</div>
      </div>
    </div>
    <div style='display:flex;justify-content:space-between;align-items:center;'>
      <button @click='prev' style='background:#1a1a1a;color:#888;border:none;padding:6px 12px;cursor:pointer;font-size:11px;'>◀</button>
      <div style='display:flex;gap:6px;'>
        <div v-for='(s,i) in slides' :key='i' @click='curr=i' :style='{background:curr===i?s.color:"#1a1a1a",width:"8px",height:"8px",borderRadius:"50%",cursor:"pointer"}'></div>
      </div>
      <button @click='next' style='background:#1a1a1a;color:#888;border:none;padding:6px 12px;cursor:pointer;font-size:11px;'>▶</button>
    </div>
  </div>`
}).mount('#car-out');

AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude

무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6

이 Vue 3 'Vue 3 실전: 캐러셀 슬라이더' 코드에서
반응성 시스템 관련 버그와 watch 누수를
찾아서 수정해줘.
ChatGPT

무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro

'Vue 3 실전: 캐러셀 슬라이더'를 활용한 실전 Vue 컴포넌트를
Composition API + script setup 문법으로 만들어줘.
Gemini

무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro

이 Vue 'Vue 3 실전: 캐러셀 슬라이더' 사용 패턴 전체를 분석하고
번들 크기·렌더링 성능·반응성 효율을
종합 점검해줘.
Grok

무료: Grok 4.1 / SuperGrok $30/mo

Vue 3 'Vue 3 실전: 캐러셀 슬라이더'가 React의 대응 기능 대비
어떤 장단점이 있는지 솔직하게 평가하고
실무 선택 기준을 알려줘.

⭐ 이것만 기억하세요
Vue 3 실전: 캐러셀 슬라이더 이 3가지만 확실히 잡으세요
1.이미지를 전부 나열하면 페이지가 길어지고, 핵심 콘텐츠를 한 공간에서 순환 표시할 방법이 없습니다
2.ref로 현재 인덱스를 관리하고, computed로 transform: translateX 값을 계산해서 슬라이드를 이동시킵니다
3.다음 챕터에서 Vue 3 트랙의 모든 개념을 종합하는 최종 미션에 도전합니다


공유하기
진행도 33 / 34