当前位置: 首页 > news >正文

vue 中支持不定高的虚拟滚动的表格 vxe-table 的使用,动态高度虚拟列表高性能表格

vue 中支持不定高的虚拟滚动的表格 vxe-table 的使用,动态高度虚拟列表高性能表格,项目的中有些场景不仅需要加载大数据量的表格,同时也要支持不固定高度,同时需要自适应行高的表格,这时候 vxe-table 就排上用场了,接下来看看如何使用。

查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table

Video_2025-12-08_095402-ezgif.com-optimize

实现原理,由于未加载的行是无法知道行高的。虚拟算法原理是估算虚拟行的行高,通过已渲染的行来纠正行高值。只有当所有数据被查看过一次之后才能达到和同等行高一样的效果。否则快速拉动滚动时会出现鼠标偏移,效果上会比同等行高略差

通过 show-overflow=false 关闭自适应行高。

<template><div><vxe-select v-model="rowSize" :options="dataOptions" @change="loadList()"></vxe-select><vxe-grid v-bind="gridOptions"></vxe-grid></div>
</template><script setup>
import { ref, reactive, nextTick } from 'vue'
import { VxeUI } from 'vxe-table'const rowSize = ref(100)const dataOptions = ref([{ label: '加载 3 行', value: 3 },{ label: '加载 20 行', value: 20 },{ label: '加载 100 行', value: 100 },{ label: '加载 500 行', value: 500 },{ label: '加载 1000 行', value: 1000 },{ label: '加载 5000 行', value: 5000 },{ label: '加载 10000 行', value: 10000 },{ label: '加载 30000 行', value: 30000 }
])// 在单元格中显示图片
const imgUrlCellRender = reactive({name: 'VxeImage',props: {width: 36,height: 36}
})const gridOptions = reactive({border: true,loading: false,showOverflow: false,height: 800,columnConfig: {resizable: true},virtualYConfig: {enabled: true,gt: 0},columns: [{ type: 'checkbox', width: 60 },{ title: '列0', field: 'col0', width: 100 },{ title: '列1', field: 'imgUrl', width: 80, cellRender: imgUrlCellRender },{ title: '列2', field: 'col2', width: 90 },{ title: '列3', field: 'col3', width: 200 },{ title: '列4', field: 'col4', width: 140 },{ title: '列5', field: 'col5', width: 300 },{ title: '列6', field: 'col6', minWidth: 160 },{ title: '列7', field: 'col7', minWidth: 120 },{ title: '列8', field: 'col8', minWidth: 120 }],data: []
})// 模拟行数据
const loadList = () => {gridOptions.loading = truesetTimeout(() => {const dataList = []for (let i = 0; i < rowSize.value; i++) {const item = {id: 10000 + i,imgUrl: i % 3 === 0 ? 'https://vxeui.com/resource/img/546.gif' : 'https://vxeui.com/resource/img/673.gif'}for (let j = 0; j < 10; j++) {if (i % 9 === 0) {item[`col${j}`] = `值_${i}_${j} 内容9内容9 内容9内容9内容9 内容9内容9内容9内容9 内容9内容9内容9内容9 内容9内容9内容9 内容9内容9`} else if (i % 8 === 0) {item[`col${j}`] = `值_${i}_${j} 内容8内容8内容8内容8`} else if (i % 7 === 0) {item[`col${j}`] = `值_${i}_${j} 内容7内容7`} else if (i % 6 === 0) {item[`col${j}`] = `值_${i}_${j} 内容6内容6内容6内容6内容6内容6内容6内容6`} else if (i % 5 === 0) {item[`col${j}`] = `值_${i}_${j} 内容5内容5内容5内容5内容5`} else if (i % 4 === 0) {item[`col${j}`] = `值_${i}_${j} 内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4内容4`} else {item[`col${j}`] = `值_${i}_${j}`}}dataList.push(item)}const startTime = Date.now()gridOptions.data = dataListgridOptions.loading = falsenextTick(() => {VxeUI.modal.message({content: `加载时间 ${Date.now() - startTime} 毫秒`,status: 'success'})})}, 350)
}loadList()
</script>

https://gitee.com/x-extends/vxe-table

http://www.jsqmd.com/news/71197/

相关文章:

  • windriver 第4章:PCI Express 概述
  • GROMACS 2025.4安装(非root用户)
  • MATLAB R2025a免费下载安装教程与激活教程超详细图文步骤(附安装包)
  • 解码string类——字符串处理
  • 新房装修公司大揭秘!一文教你避坑选好公司 - 品牌测评鉴赏家
  • 新手装修必看!第一次选对装修公司,省心攻略全解析 - 品牌测评鉴赏家
  • Docker Swarm 的负载均衡和平滑切换原理 - 实践
  • windriver 第3章: 安装WinDriver
  • 2025年推荐实力户外滑梯厂家飞友,以专业品质守护儿童欢乐时光 - 速递信息
  • 2025整装公司排行榜发布:十大整装品牌引领行业新趋势 - 速递信息
  • day3 Java基础3
  • 头歌MySQL——单表查询 - 详解
  • windriver 第2章: 了解设备驱动程序
  • 纯棉卫生巾推荐,4款热门产品深度横评,看完这篇再下单! - 速递信息
  • 2025年整装公司口碑推荐实力TOP榜|十大装修公司对比 - 速递信息
  • 2025年整装公司权威推荐榜:十大特色装修公司满足不同需求 - 速递信息
  • 2025整装公司排名榜!十强家装品牌核心优势对比 - 速递信息
  • 解决IDEA中项目目录的底色变黄
  • 2025年最新幼儿园教玩具品牌推荐,守护孩子成长——飞友用硬核筑牢成长防线 - 速递信息
  • 全屋整装公司品牌十强有哪些?2025排名与品牌解析 - 速递信息
  • 吐血整理!揭秘2025年新房装修公司哪家靠谱! - 品牌测评鉴赏家
  • 第五十九篇
  • 创建用户赋予权限
  • 2025 最新实测:AI 学习机是智商税吗?有没有用 + 高性价比品牌清单 - 品牌测评鉴赏家
  • AI 学习机品牌推荐(2025 年 12 月最新) 高性价比机型选购指南 - 品牌测评鉴赏家
  • 任意地址写basectf_format_string_level1
  • 3
  • 还在为论文开题报告发愁?7款免费AI工具帮你轻松搞定! - 麟书学长
  • 2025.12.10博客
  • 2025.12.10博客