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

Vue 3 실전: 무한 스크롤


핵심 개념

IntersectionObserver와 Vue 라이프사이클로 무한 스크롤을 구현합니다. 스크롤 하단 감지 시 자동으로 데이터를 추가합니다. 옵저버를 지우며 무한 스크롤이 어떻게 멈추는지 확인하십시오.

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


const{createApp,ref,onMounted,onUnmounted}=Vue;
createApp({
  setup(){
    const items=ref(Array.from({length:10},(_,i)=>({id:i+1,model:'T-'+String(800+i),threat:Math.floor(Math.random()*10)+1})));
    const loading=ref(false);const sentinel=ref(null);let observer;
    const loadMore=()=>{
      loading.value=true;
      setTimeout(()=>{
        const start=items.value.length;
        items.value.push(...Array.from({length:5},(_,i)=>({id:start+i+1,model:'T-'+String(800+start+i),threat:Math.floor(Math.random()*10)+1})));
        loading.value=false;
      },500);
    };
    onMounted(()=>{
      observer=new IntersectionObserver(entries=>{if(entries[0].isIntersecting&&!loading.value)loadMore();},{threshold:0.1});
      if(sentinel.value)observer.observe(sentinel.value);
    });
    onUnmounted(()=>observer?.disconnect());
    return{items,loading,sentinel};
  },
  template:`<div style='max-height:200px;overflow-y:auto;'>
    <div v-for='u in items' :key='u.id' style='display:flex;justify-content:space-between;padding:6px;border-bottom:1px solid #111;font-size:11px;'>
      <span style='color:#f59e0b;'>{{u.model}}</span>
      <span :style='{color:u.threat>=9?"#10b981":u.threat>=7?"#f59e0b":"#22c55e"}'>{{u.threat}}</span>
    </div>
    <div ref='sentinel' style='padding:8px;text-align:center;font-size:10px;color:#555;'>
      {{loading?"LOADING...":"↓ SCROLL"}}
    </div>
  </div>`
}).mount('#inf-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.한 번에 전체 데이터를 로딩하면 초기 렌더링이 느리고, DOM 노드가 많아져 스크롤 성능이 저하됩니다
2.IntersectionObserver로 하단 감지 → onMounted에서 등록 → 감지 시 다음 페이지 fetch하는 3단계 패턴입니다
3.다음 챕터에서 시스템 테마를 전환하는 다크모드 토글을 구현합니다


공유하기
진행도 25 / 34