vxe-table 渲染百万行数据性能对比,超大量百万级表格渲染;如何在 vue 渲染百万行数据;当在开发项目时,遇到需要流畅支持百万级数据的表格时, vxe-table 就可以非常合适了,不仅支持强大的功能,虚拟滚动渲染超大数据量也支持。
查看官网:https://vxetable.cn
gitbub:https://github.com/x-extends/vxe-table
gitee:https://gitee.com/x-extends/vxe-table
安装
npm install vxe-table@4.12.2
// ...
import VxeUITable from 'vxe-table'
import 'vxe-table/lib/style.css'
// ...
createApp(App).use(VxeUITable).mount('#app')
// ...
效果
代码
<template>
<div>
<p>
<vxe-button @click="loadList(5)">5行</vxe-button>
<vxe-button @click="loadList(1000)">1k行</vxe-button>
<vxe-button @click="loadList(10000)">1w行</vxe-button>
<vxe-button @click="loadList(100000)">10w行</vxe-button>
<vxe-button @click="loadList(500000)">50w行</vxe-button>
<vxe-button @click="loadList(1000000)">100w行</vxe-button>
<vxe-button @click="loadList(2000000)">200w行</vxe-button>
</p>
<vxe-grid ref="gridRef" v-bind="gridOptions"></vxe-grid>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { VxeUI } from 'vxe-table'
const gridRef = ref()
const gridOptions = reactive({
border: true,
showOverflow: true,
height: 800,
loading: false,
columnConfig: {
resizable: true
},
scrollY: {
enabled: true,
gt: 0
},
columns: [
{ type: 'checkbox', width: 60 },
{ type: 'seq', title: '序号', width: 100 },
{ field: 'name', title: 'Name', minWidth: 180 },
{ field: 'role', title: 'Role', width: 200 },
{ field: 'num', title: 'Num', width: 200 },
{ field: 'address', title: 'Address', width: 200 }
],
data: []
})
// 模拟行数据
const loadList = (size = 200) => {
gridOptions.loading = true
setTimeout(() => {
const dataList = []
for (let i = 0; i < size; i++) {
dataList.push({
id: i,
name: `名称${i} 名称名称 称`,
role: `role ${i}`,
num: 20,
address: 'shenzhen shen'
})
}
const $grid = gridRef.value
if ($grid) {
const startTime = Date.now()
$grid.loadData(dataList).then(() => {
VxeUI.modal.message({
content: `加载时间 ${Date.now() - startTime} 毫秒`,
status: 'success'
})
gridOptions.loading = false
})
}
}, 350)
}
loadList(500)
</script>
https://gitee.com/x-extends/vxe-table