更新记录
1.0.1(2026-03-30)
- 将
readme.md中的 HTML 视频标签改为更通用的 Markdown 视频链接
1.0.0(2026-03-30)
- 初始化
hans-virtual-listuni_modules 组件目录
平台兼容性
uni-app(5.01)
| Vue2 | Vue3 | Chrome | Safari | app-vue | app-nvue | Android | iOS | 鸿蒙 |
|---|---|---|---|---|---|---|---|---|
| √ | √ | - | - | - | - | - | - | - |
| 微信小程序 | 支付宝小程序 | 抖音小程序 | 百度小程序 | 快手小程序 | 京东小程序 | 鸿蒙元服务 | QQ小程序 | 飞书小程序 | 小红书小程序 | 快应用-华为 | 快应用-联盟 |
|---|---|---|---|---|---|---|---|---|---|---|---|
| - | - | - | - | - | - | - | - | - | - | - | - |
hans-virtual-list
演示视频
Android
iOS
hans-virtual-list 是一个用于 uni-app 的虚拟列表组件,适合长列表场景。
当前不兼容 uni-app x。
支持三种高度模式:
fixed:固定行高estimate:使用估算高度dynamic:先估算,再按实际渲染结果回填高度
基础用法
<template>
<hans-virtual-list
:items="items"
key-field="id"
:height="560"
height-mode="dynamic"
:estimated-item-height="96"
:overscan="8"
>
<template #default="{ item, index, height, measured }">
<view class="row">
<text>{{ index }}. {{ item.title }}</text>
<text>{{ height }} / {{ measured ? 'measured' : 'estimated' }}</text>
</view>
</template>
</hans-virtual-list>
</template>
<script>
import HansVirtualList from '@/uni_modules/hans-virtual-list/components/hans-virtual-list/hans-virtual-list.vue'
export default {
components: {
HansVirtualList,
},
data() {
return {
items: [],
}
},
}
</script>
Props
| 参数 | 类型 | 默认值 | 说明 |
|---|---|---|---|
items |
Array |
[] |
列表数据 |
keyField |
String |
'id' |
列表项唯一键字段 |
heightMode |
String |
'dynamic' |
高度模式,可选 fixed / estimate / dynamic |
itemHeight |
Number |
0 |
固定行高,fixed 模式下使用 |
estimatedItemHeight |
Number |
80 |
估算行高,estimate / dynamic 模式下使用 |
overscan |
Number |
6 |
可视区前后额外渲染的条数 |
height |
Number |
0 |
列表容器高度,单位 px |
scrollTopValue |
Number |
0 |
外部控制滚动位置 |
usePretext |
Boolean |
true |
是否启用文本高度预测 |
pretextOptions |
Object |
{} |
文本高度预测参数 |
pretextVersion |
String \| Number \| Boolean |
'' |
预测配置版本号,变更后会重新计算 |
debugPretext |
Boolean |
false |
是否开启预测相关调试事件 |
itemLayoutFingerprint |
Function |
null |
自定义布局指纹,用于内容变化后触发重新测量 |
pretextOptions
启用 usePretext 时,可通过 pretextOptions 传入文本预测参数。常用字段:
| 字段 | 类型 | 说明 |
|---|---|---|
font |
String |
文本字体声明,例如 14px sans-serif |
lineHeight |
Number |
文本行高 |
width |
Number |
文本可用宽度 |
extraHeight |
Number |
除正文文本外需要补上的额外高度 |
getText |
Function |
从列表项中提取要参与预测的文本 |
示例:
pretextOptions: {
font: '14px sans-serif',
lineHeight: 22,
width: 280,
extraHeight: 48,
getText(item) {
return item && item.content ? item.content : ''
},
}
插槽
默认插槽参数:
| 字段 | 说明 |
|---|---|
item |
当前列表项数据 |
index |
当前索引 |
height |
当前项高度 |
measured |
是否已经完成真实测量 |
isFastScrolling |
当前是否处于快速滚动状态 |
scrollDirection |
当前滚动方向,forward 或 backward |
事件
| 事件 | 说明 |
|---|---|
scroll |
列表滚动时触发 |
range-change |
可见区变化时触发 |
reach-bottom |
接近底部时触发 |
item-resize |
某一项真实高度更新时触发 |
pretext-status-change |
文本预测状态变化,需 debugPretext=true |
pretext-scheduled |
文本预测任务调度,需 debugPretext=true |
pretext-patched |
文本预测结果写回,需 debugPretext=true |
使用建议
- 列表项高度稳定时优先用
fixed - 高度不固定但可大致预估时用
estimate - 高度依赖真实渲染结果时用
dynamic keyField必须稳定且唯一,否则高度缓存会错位dynamic模式下如果列表项内容会变化,建议提供itemLayoutFingerprint

收藏人数:
购买普通授权版(
试用
赞赏(0)
下载 280
赞赏 0
下载 11694378
赞赏 1898
赞赏
京公网安备:11010802035340号