문서 가상화

UIVirtualList

화면에 보이는 구간의 목록을 렌더링합니다.

기본 사용법

변경 기록 5만 건 탐색

스크롤하면 화면에 보이는 범위가 바뀝니다. 아래에서 전체 기록과 DOM에 렌더링한 행 수를 비교할 수 있습니다.

변경 기록50,000건
1–1번 표시, DOM 0행 렌더링
<script setup lang="ts">
import { UIDataLabel, UIDataSurface, UIVirtualList } from "@connextable/ui";
import { ref } from "vue";

const rows = Array.from({ length: 50_000 }, (_, index) => index + 1);
const visible = ref({ first: 1, last: 1, rendered: 0 });
const number = new Intl.NumberFormat("ko-KR");
const changes = ["문서 게시", "담당자 변경", "검토 완료", "일정 등록"];
</script>

<template>
  <UIDataSurface>
    <template #toolbar
      ><strong>변경 기록</strong
      ><output>{{ number.format(rows.length) }}건</output></template
    >
    <UIVirtualList
      :items="rows"
      :get-i-d="(id) => id"
      :size-policy="{ kind: 'fixed', extent: 48 }"
      :overscan="84"
      role="region"
      tabindex="0"
      aria-label="변경 기록 5만 건"
      @plan-change="
        (plan) => {
          const onScreen = plan.placements.filter((item) => item.visible);
          if (onScreen.length)
            visible = {
              first: Number(onScreen[0]?.id),
              last: Number(onScreen.at(-1)?.id),
              rendered: plan.placements.length,
            };
        }
      "
    >
      <template #item="{ value }">
        <span class="activity-row">
          <UIDataLabel :label="changes[(value - 1) % changes.length]!" />
          <span class="activity-row__number">#{{ number.format(value) }}</span>
        </span>
      </template>
    </UIVirtualList>
    <template #footer>
      <output
        >{{ number.format(visible.first) }}–{{ number.format(visible.last) }}번
        표시, DOM {{ visible.rendered }}행 렌더링</output
      >
    </template>
  </UIDataSurface>
</template>

<style scoped>
.activity-row {
  display: flex;
  flex: 1;
  align-items: center;
  justify-content: space-between;
  gap: var(--ui-space-sm);
}

.activity-row__number {
  color: var(--ui-color-text-muted);
  font-variant-numeric: tabular-nums;
}
</style>

설정과 동작

가로 목록 스크롤

가로로 스크롤하며 현재 범위에 있는 항목을 표시합니다.

다른 높이의 행

두 줄짜리 행의 실제 높이를 측정해 다음 행이 겹치지 않습니다.

제목과 목록을 함께 스크롤

바깥 스크롤 영역이 제목과 가상 목록을 함께 옮깁니다.

실전 예제

가상 목록 검색

‘서울’을 검색하고 스크롤해 보세요. 일치하는 항목이 없으면 빈 상태를 표시합니다.

이전 기록을 추가하며 현재 위치 유지

목록을 아래로 스크롤한 다음 이전 기록을 추가해 첫 항목이 유지되는지 확인합니다.

끝에 닿으면 다음 기록 불러오기

불러온 기록의 마지막에 가까워지면 가상 응답으로 40건씩 추가합니다.

새 메시지 따라가기

이전 메시지를 읽는 동안 새 메시지를 받아도 위치가 유지됩니다. 최신으로 이동한 다음에는 새 메시지를 따라갑니다.

보이는 범위만 요청하고 저장

9,001번으로 이동하면 그 주변 행을 요청합니다. 로딩 전후 행 높이가 유지되고 다시 돌아오면 받아 둔 데이터를 사용합니다.

주요 API

속성과 모델

items타입readonly Value[]

가상화할 전체 항목입니다.

가로 목록 스크롤 예제
getID

앞이나 뒤에 기록을 추가해도 유지되는 항목 식별자입니다.

size-policy타입VirtualSizePolicy<Value>

행의 크기를 지정하거나 추정하거나 측정하는 방식입니다.

가로 목록 스크롤 예제
overscan타입number | Partial<Insets> | undefined

뷰포트 바깥에서 미리 준비할 범위입니다.

변경 기록 5만 건 탐색 예제

슬롯

#item / #empty

현재 항목의 value와 위치를 받거나 검색 결과가 없을 때의 콘텐츠를 표시합니다.

가로 목록 스크롤 예제

이벤트와 명령

plan-change

배치가 갱신될 때 호출됩니다. placements에서 표시 범위와 마운트된 항목을 읽습니다.

전체 속성, 이벤트와 슬롯

UIVirtualList

size-policy필수
VirtualSizePolicy<Value>
axis
LinearAxis | undefined
gap
number | undefined
items필수
readonly Value[]
get-i-d필수
VirtualCollectionIDResolver<Value, ID>
overscan
number | Partial<Insets> | undefined
viewport-insets
number | Partial<Insets> | undefined
scrollport
VirtualizerScrollportTarget | null | undefined
max-items
number | undefined
initial-viewport
Rect | undefined
as
string | undefined
content-as
string | undefined
item-as
string | undefined
item-attributes
((value: Value, index: number) => Readonly<Record<string, unknown>>) | undefined
part-attributes
Readonly<Partial<Record<"footer" | "surface" | "header", Readonly<Record<string, unknown>>>>> | undefined
@state-change
(state: LinearLayoutState<ID>) => unknown
@plan-change
(plan: VirtualLayoutPlan<ID>) => unknown
@error
(error: SectileError<VirtualErrorCode>) => void
#header
() => VNodeChild
#item
(props: VirtualListSlotProps<Value, ID>) => VNodeChild
#empty
() => VNodeChild
#footer
() => VNodeChild