
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
@gaplin/vue-virtual-tree
Advanced tools
一款基于vue2.x,同时支持少量数据或大量数据、多种功能和虚拟滚动(支持固定节点高度和动态节点高度)的树组件。
基于element-ui(License:MIT)中抽取的tree样式和功能,结合vue-virtual-scroller(License:MIT)所做的树组件。
npm install @gaplin/vue-virtual-tree
或
yarn add @gaplin/vue-virtual-tree
安装sass-loader,命令:npm add sass-loader@8.0.2
安装node-sass,命令:npm add node-sass@4.14.1
在 main.js 文件中引入:
import Vue from "vue";
import VueVirtualTree from "@gaplin/vue-virtual-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@gaplin/vue-virtual-tree/src/assets/index.scss"
Vue.use(VueVirtualTree)
在组件中引入:
import VueVirtualTree from "@gaplin/vue-virtual-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@gaplin/vue-virtual-tree/src/assets/index.scss"
export default {
components: {
VueVirtualTree
}
}
:warning: 在使用虚拟滚动时,必须设置 node-key。
<template>
<div class="ve-tree" style="height:calc(100vh - 20px)">
<!-- 不使用虚拟滚动时只需去掉height参数即可 -->
<vue-virtual-tree
ref="veTree"
node-key="id"
height="calc(100vh - 20px)"
:data="treeData"
:props="props"
></vue-virtual-tree>
</div>
</template>
<script>
export default {
data() {
return {
props: {
label: "name",
children: "children"
},
treeData: []
};
},
created() {
const data = [],
root = 8,
children = 3,
base = 1000;
for (let i = 0; i < root; i++) {
data.push({
id: `${i}`,
name: `test-${i}`,
children: []
});
for (let j = 0; j < children; j++) {
data[i].children.push({
id: `${i}-${j}`,
name: `test-${i}-${j}`,
children: []
});
for (let k = 0; k < base; k++) {
data[i].children[j].children.push({
id: `${i}-${j}-${k}`,
name: `test-${i}-${j}-${k}`
});
}
}
}
this.treeData = data;
}
};
</script>
通过新建一个样式文件,如:ve-tree-var.scss,写入以下内容:
/* 改变主题色变量 */
$--color-primary: #ea5404;
/* 改变 icon 字体路径变量,必需 */
$--font-path: "~@gaplin/vue-virtual-tree/src/assets/fonts";
@import "@gaplin/vue-virtual-tree/src/assets/index.scss";
:warning: 需要注意的是,覆盖字体路径变量是必需的,将其赋值为 @gaplin/vue-virtual-tree 中 icon 图标所在的相对路径即可。
然后在 main.js 中直接引入以上样式文件即可:
import Vue from 'vue'
import VueVirtualTree from "@gaplin/vue-virtual-tree";
import "./css/ve-tree-var.scss"
Vue.use(VueVirtualTree)
来自element-ui 官方文档
需要使用虚拟滚动时,增加 height 属性即可,如:
<vue-virtual-tree :data="data" height="calc(100vh - 20px)" :props="defaultProps" @node-click="handleNodeClick"></vue-virtual-tree>
<!-- 默认开启固定高度模式,子item动态高度模式需要手动开启,如下:isDynamic为true开启,配合minItemSize设置第一次渲染时的子item最小高度 -->
<vue-virtual-tree :data="data" height="calc(100vh - 20px)" :props="defaultProps" @node-click="handleNodeClick" :minItemSize="50" isDynamic></vue-virtual-tree>
FAQs
A virtual tree component based on Vue2
We found that @gaplin/vue-virtual-tree demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.