Skip to content

FxVirtualList 虚拟列表

大数据量列表 / 网格的虚拟滚动组件,只渲染可见窗口 + 预渲染项,避免万级 DOM 节点卡顿。采用 builder 工厂 + render 函数模式,4 个组件共享滚动/渲染逻辑,仅注入不同的尺寸计算函数。

组件维度尺寸适用
FxFixedSizeList一维行高固定长列表,项高度一致
FxDynamicSizeList一维行高按索引变化长列表,项高度不等
FxFixedSizeGrid二维行高/列宽固定表格 / 矩阵
FxDynamicSizeGrid二维行高/列宽按索引变化不规则表格

FxVirtualList 属于 @fx/components

何时使用

  • 列表 / 表格项数 > 200,全量渲染出现卡顿
  • 选择器 / 树形 / 表格内部需要长列表渲染

固定行高列表(FxFixedSizeList)

itemSize 为数字,total 指定总项数,容器需给固定 height

动态行高列表(FxDynamicSizeList)

itemSize 为函数 (idx) => numberestimatedItemSize 为未测量项的预估行高。内部用二分 + 指数搜索定位。

横向列表(layout="horizontal")

layout="horizontal" 时切换为横向虚拟滚动:itemSize 表示每项宽度width 是可见宽,纵向滚动条自动切换为底部横向滚动条。

固定网格(FxFixedSizeGrid)

total-row × total-column 网格,row-height / column-width 为数字。Grid 容器 overflow: hidden,滚动靠 wheel / 触摸 / scrollTo,配套横向 + 纵向两条自定义滚动条。

动态网格(FxDynamicSizeGrid)

row-height / column-width 为函数,按索引返回尺寸;estimated-row-height / estimated-column-width 为未测量项的预估值。

API

List props(FxFixedSizeList / FxDynamicSizeList)

属性说明类型默认值
total总项数number(必填)
itemSize行高。FixedSize 传数字;DynamicSize 传函数number | ((idx) => number)(必填)
height容器高string | number(必填)
width容器宽(横向 layout 时必填)string | number
layout滚动方向'vertical' | 'horizontal'vertical
cache上下预渲染项数number2
init-scroll-offset初始滚动偏移number0
estimated-item-size预估行高(仅 DynamicSize)number50
use-is-scrolling向 slot 提供 isScrollingbooleanfalse
direction书写方向'ltr' | 'rtl'ltr
inner-width内层宽(横向 layout)string | number
scrollbar-always-on自定义滚动条常驻booleanfalse

Grid props(FxFixedSizeGrid / FxDynamicSizeGrid)

属性说明类型默认值
total-row总行数number(必填)
total-column总列数number(必填)
row-height行高。FixedSize 数字;DynamicSize 函数number | ((idx) => number)(必填)
column-width列宽。FixedSize 数字;DynamicSize 函数number | ((idx) => number)(必填)
height容器高string | number(必填)
width容器宽string | number(必填)
row-cache行预渲染数number2
column-cache列预渲染数number2
init-scroll-left初始横向偏移number0
init-scroll-top初始纵向偏移number0
estimated-row-height预估行高(仅 DynamicSize)number50
estimated-column-width预估列宽(仅 DynamicSize)number50
item-key单元格 key 生成函数(args) => string | number${row}:${col}
use-is-scrolling向 slot 提供 isScrollingbooleanfalse
direction书写方向'ltr' | 'rtl'ltr
h-scrollbar-size横向滚动条尺寸(px)number6
v-scrollbar-size纵向滚动条尺寸(px)number6
scrollbar-start-gap滚动条起始间距number0
scrollbar-end-gap滚动条末尾间距number2
rolearia rolestring

Slots

List default{ index, style, data?, isScrolling? }Grid default{ rowIndex, columnIndex, style, data?, isScrolling? }

style 必须绑定到项根元素(组件靠 absolute 定位摆放每项)。

Events

事件名说明回调参数
item-rendered可见区渲染变化List: (cacheStart, cacheEnd, visibleStart, visibleEnd);Grid: (params) 对象含行列的 cacheStart/End + visibleStart/End
scroll滚动时List: (scrollDir, scrollOffset, updateRequested);Grid: (params) 对象含 xAxisScrollDir / yAxisScrollDir / scrollLeft / scrollTop / updateRequested

Exposes

ListscrollTo(offset) / scrollToItem(idx, alignment?) / states / windowRef / innerRef / getItemStyleCache / resetScrollTop

GridscrollTo({ scrollLeft?, scrollTop? }) / scrollToItem(rowIdx?, colIdx?, alignment?) / states / windowRef / innerRef / getItemStyleCache / touchStartX / touchStartY / handleTouchStart / handleTouchMove

alignment 取值:'auto' | 'smart' | 'start' | 'center' | 'end'

说明

  • List 项 style 必须绑定:slot 根元素 :style="style",组件靠 absolute 定位摆放每项。
  • List 隐藏原生滚动条:List 用自定义滚动条,原生滚动条需自行隐藏(:deep(.fx-vl__window) { scrollbar-width: none })。
  • Grid 容器 overflow: hidden:不显示原生滚动条,滚动靠 wheel / 触摸 / scrollTo