본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Vue DeferredContent 컴포넌트

원문 보기 위키 갱신

DeferredContent는 처음에는 뷰포트에 없던 콘텐츠의 로딩을 미루다가, 스크롤로 보이는 순간 로드하는 컴포넌트예요. 무거운 데이터 테이블이나 이미지를 지연 로딩(lazy load)할 때 유용해요.

출처: 문서

본문

Vue Deferred Content Component

DeferredContent postpones the loading the content that is initially not in the viewport until it becomes visible on scroll.

Import

import DeferredContent from 'primevue/deferredcontent';

Accessibility

Screen Reader DeferredContent는 다양한 용도로 활용될 수 있어서 특정 role을 강제하지 않아요. 실제로 카드가 표시(presentational) 목적으로만 쓰인다면 role이 필요 없을 수도 있어요. 모든 유효한 속성은 컨테이너 요소로 전달되므로 landmark 같은 role과 aria-live 같은 속성을 완전히 직접 제어할 수 있어요. Keyboard Support 이 컴포넌트에는 인터랙티브 요소가 없어요.

<DeferredContent role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
    Content
</DeferredContent>

Basic

DeferredContent는 대상을 감싸서 사용해요.

<DeferredContent @load="onImageLoad">
    <img src="/images/nature/nature4.jpg" alt="Nature" class="rounded-xl w-full md:w-96 block sm:mx-auto" />
</DeferredContent>

DataTable

테이블이 뷰포트에 보이는 순간 fetch를 트리거하는 실용적인 예제예요.

<DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
    <DataTable :value="products">
        <Column field="code" header="Code"></Column>
        <Column field="name" header="Name"></Column>
        <Column field="category" header="Category"></Column>
        <Column field="quantity" header="Quantity"></Column>
    </DataTable>
</DeferredContent>
Composition API Example
<template>
    <div class="card">
        <Toast />
        <div style="height: 800px">Scroll down to lazy load a DataTable.</div>

        <DeferredContent @load="onDataLoad" role="region" aria-live="polite" aria-label="Content loaded after page scrolled down">
            <DataTable :value="products">
                <Column field="code" header="Code"></Column>
                <Column field="name" header="Name"></Column>
                <Column field="category" header="Category"></Column>
                <Column field="quantity" header="Quantity"></Column>
            </DataTable>
        </DeferredContent>
    </div>
</template>

<script setup>
import { ref } from 'vue';
import { ProductService } from '@/service/ProductService';

const products = ref(null);

const onDataLoad = () => {
    ProductService.getProductsSmall().then((data) => (products.value = data));
    toast.add({ severity: 'success', summary: 'Data Initialized', detail: 'Render Completed', life: 2000 });
};
<\/script>

Deferred Content

Props

Name Type Default Description
dt any - It generates scoped CSS variables using design tokens for the component.
pt PassThrough - Used to pass attributes to DOM elements inside the component.
ptOptions any - Used to configure passthrough(pt) options of the component.
unstyled boolean false When enabled, it removes component related styles in the core.

Pass Through Options

Name Type Description
root DeferredContentPassThroughOptionType Used to pass attributes to the root's DOM element.
hooks any Used to manage all lifecycle hooks.

더 알아보기 (Learn more)