组件/VirtualList 虚拟列表
通用组件

VirtualList 虚拟列表

用于长列表渲染场景,降低 DOM 数量提升性能。

该页面由 AI 迁移生成,请谨慎使用

内容已迁移完成,但仍建议结合源码和人工评审结果使用。

VirtualList 虚拟列表

用于长列表渲染场景,降低 DOM 数量提升性能。

基础用法

示例即将加载...
<script setup lang="ts">
const items = Array.from({ length: 100 }, (_, i) => `Item ${i + 1}`)
</script>

<template>
  <TxVirtualList :items="items" :item-height="36" height="240px">
    <template #item="{ item, index }">
      <div style="padding: 6px 12px; width: 100%;">
        {{ index + 1 }}. {{ item }}
      </div>
    </template>
  </TxVirtualList>
</template>

API

TxVirtualList Props

属性名类型默认值说明
itemsany[][]数据列表
itemHeightnumber-单项高度
heightnumber | string320容器高度
overscannumber4预渲染数量
itemKeystring | (item, index) => string | numberindex唯一 key

Events

事件名参数说明
scroll({ scrollTop, startIndex, endIndex })滚动事件

Slots

名称说明
item自定义项渲染

Expose

名称说明
scrollToIndex(index)滚动到指定索引
scrollToTop()滚动到顶部
scrollToBottom()滚动到底部