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

vue vxe-tree 树组件加载大量节点数据,虚拟滚动的用法

vue vxe-tree 树组件加载大量节点数据,虚拟滚动的用法

查看官网:https://vxeui.com

上万节点数据

在这里插入图片描述

当数据量达到上万时,通过数据双向绑定将会影响性能,可以通过调用 loadData 来加载数据

<template><div><vxe-button status="primary" @click="expandAllEvent">展开所有</vxe-button><vxe-button status="primary" @click="clearAllEvent">关闭所有</vxe-button><vxe-tree ref="treeRef" v-bind="treeOptions"></vxe-tree></div>
</template><script setup>
import { ref, reactive } from 'vue'const treeRef = ref()const treeOptions = reactive({loading: false,height: 400,transform: true,showCheckbox: true,titleField: 'name'
//  默认启用  
//  virtualYConfig: {
//    enabled: true,
//    gt: 0
//  }
})const loadList = () => {treeOptions.loading = truefetch('/resource/json/provinces_list.json').then(res => res.json()).then((data) => {treeOptions.loading = falseconst $tree = treeRef.valueif ($tree) {$tree.loadData(data)}})
}const expandAllEvent = () => {const $tree = treeRef.valueif ($tree) {$tree.setAllExpandNode(true)}
}
const clearAllEvent = () => {const $tree = treeRef.valueif ($tree) {$tree.setAllExpandNode(false)}
}loadList()
</script>

连接线

在这里插入图片描述
在这里插入图片描述

<template><div><vxe-tree :data="treeList" transform show-checkbox show-line></vxe-tree></div>
</template><script setup>
import { ref } from 'vue'const treeList = ref([{ title: '节点2', id: '2', parentId: null },{ title: '节点3', id: '3', parentId: null },{ title: '节点3-1', id: '31', parentId: '3' },{ title: '节点3-2', id: '32', parentId: '3' },{ title: '节点3-2-1', id: '321', parentId: '32' },{ title: '节点3-2-2', id: '322', parentId: '32' },{ title: '节点3-3', id: '33', parentId: '3' },{ title: '节点3-3-1', id: '331', parentId: '33' },{ title: '节点3-3-2', id: '332', parentId: '33' },{ title: '节点3-3-3', id: '333', parentId: '33' },{ title: '节点3-4', id: '34', parentId: '3' },{ title: '节点4', id: '4', parentId: null },{ title: '节点4-1', id: '41', parentId: '4' },{ title: '节点4-1-1', id: '411', parentId: '42' },{ title: '节点4-1-2', id: '412', parentId: '42' },{ title: '节点4-2', id: '42', parentId: '4' },{ title: '节点4-3', id: '43', parentId: '4' },{ title: '节点4-3-1', id: '431', parentId: '43' },{ title: '节点4-3-2', id: '432', parentId: '43' },{ title: '节点5', id: '5', parentId: null }
])
</script>

过滤节点

通过 filter-value 就可以设置过滤功能,通过 filter-config.autoExpandAll 来设置过滤后自动展开与收起
在这里插入图片描述

<template><div><div><vxe-input v-model="treeOptions.filterValue" type="search" clearable></vxe-input></div><vxe-tree v-bind="treeOptions"></vxe-tree></div>
</template><script setup>
import { reactive } from 'vue'const treeOptions = reactive({transform: true,filterValue: '',filterConfig: {autoExpandAll: true},data: [{ title: '节点2', id: '2', parentId: null },{ title: '节点3', id: '3', parentId: null },{ title: '节点3-1', id: '31', parentId: '3' },{ title: '节点3-2', id: '32', parentId: '3' },{ title: '节点3-2-1', id: '321', parentId: '32' },{ title: '节点3-2-2', id: '322', parentId: '32' },{ title: '节点3-3', id: '33', parentId: '3' },{ title: '节点3-3-1', id: '331', parentId: '33' },{ title: '节点3-3-2', id: '332', parentId: '33' },{ title: '节点3-3-3', id: '333', parentId: '33' },{ title: '节点3-4', id: '34', parentId: '3' },{ title: '节点4', id: '4', parentId: null },{ title: '节点4-1', id: '41', parentId: '4' },{ title: '节点4-1-1', id: '411', parentId: '42' },{ title: '节点4-1-2', id: '412', parentId: '42' },{ title: '节点4-2', id: '42', parentId: '4' },{ title: '节点4-3', id: '43', parentId: '4' },{ title: '节点4-3-1', id: '431', parentId: '43' },{ title: '节点4-3-2', id: '432', parentId: '43' },{ title: '节点5', id: '5', parentId: null }]
})
</script>
http://www.xdnf.cn/news/1119583.html

相关文章:

  • 【AutoCAD全网最新版】AutoCAD 2026 保姆级下载安装注册使用详细图文教程
  • 借助DeepSeek编写输出漂亮表格的chdb客户端
  • [源力觉醒 创作者计划]_文心大模型4.5开源部署指南:从技术架构到实战落地
  • sfe_py的应力云图计算与显示step by step
  • 【LeetCode240.搜索二维矩阵Ⅱ】以及变式
  • iOS高级开发工程师面试——RunLoop
  • C++类模版与友元
  • 大数据领域开山鼻祖组件Hadoop核心架构设计
  • 50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | GithubProfies(GitHub 个人资料)
  • 编译器 VS 解释器
  • 电脑升级Experience
  • Linux操作系统之信号:信号的产生
  • 【C++进阶】---- 多态
  • 鹧鸪云:别墅光储项目方案设计的最终选择
  • 【Linux系统】进程切换 | 进程调度——O(1)调度队列
  • Linux:3_基础开发⼯具
  • 【Linux】基本指令详解(一) 树状文件结构、家目录、绝对/相对路径、linux文件类型
  • 使用systemctl命令控制软件的启动和关闭
  • 打破空间边界!Nas-Cab用模块化设计重构个人存储逻辑
  • 各种开发语言主要语法对比
  • Codeforces Round 1019 (Div. 2) A-D
  • GPU网络运维
  • UV vs Pip:Python 包管理的革命性进化
  • 【安卓笔记】进程和线程的基础知识
  • 实现高效、可靠的基于骨骼的人体姿态建模(第二章 基于三维人体姿态回归的语义图卷积网络)
  • 马蹄集 BD202401补给
  • Elasticsearch 9.x 升级变化
  • Swift 解 LeetCode 326:两种方法判断是否是 3 的幂,含循环与数学技巧
  • APK安装器(安卓端)一键解除VX限制!轻松安装各种手机应用
  • 一键获取android公钥/ios公钥工具