npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@fit2cloud-ui/vue-virtual-tree

v1.0.1

Published

基于Element-ui和vue-virtual-scroller实现的Vue2版本的虚拟树形组件,支持固定高度和动态高度两种模式

Downloads

37

Readme

vue-virtual-tree

介绍

一款基于 vue2.x,同时支持少量数据或大量数据、多种功能和虚拟滚动(支持固定节点高度和动态节点高度)的树组件。

基于element-ui(License:MIT)中抽取的 tree 样式和功能,结合vue-virtual-scroller(License:MIT)所做的树组件。

v1.0 功能列表 npm

  • 大数据量支持虚拟滚动(支持固定节点高度和动态节点高度)
  • 基本树形数据的展示
  • 支持 checkbox 选择
  • 支持懒加载
  • 默认展开和默认选中
  • 禁用节点
  • 通过多种方式选中节点和获取选中的节点信息
  • 支持自定义节点内容
  • 支持节点过滤
  • 非虚拟滚动下,支持手风琴模式
  • 非懒加载时,支持节点拖拽

特点

  • 支持虚拟滚动
  • 不仅支持大数据量的树形数据展示,还支持数据的操作和更改
  • 不仅支持固定高度的子 item 的虚拟滚动,还支持子 item 动态高度的虚拟滚动

安装

npm install @fit2cloud-ui/vue-virtual-tree

yarn add @fit2cloud-ui/vue-virtual-tree

引入

全局引入

main.js 文件中引入:

import Vue from "vue";
import VueVirtualTree from "@fit2cloud-ui/vue-virtual-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@fit2cloud-ui/vue-virtual-tree/src/assets/index.scss"

Vue.use(VueVirtualTree)

组件引入

在组件中引入:

import VueVirtualTree from "@fit2cloud-ui/vue-virtual-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@fit2cloud-ui/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>

在项目中改变 SCSS 变量

通过新建一个样式文件,如:ve-tree-var.scss,写入以下内容:

/* 改变主题色变量 */
$--color-primary: #ea5404;

/* 改变 icon 字体路径变量,必需 */
$--font-path: "~@fit2cloud-ui/vue-virtual-tree/src/assets/fonts";

@import "@fit2cloud-ui/vue-virtual-tree/src/assets/index.scss";

:warning: 需要注意的是,覆盖字体路径变量是必需的,将其赋值为 @fit2cloud-ui/vue-virtual-tree 中 icon 图标所在的相对路径即可。

然后在 main.js 中直接引入以上样式文件即可:

import Vue from 'vue'
import VueVirtualTree from "@fit2cloud-ui/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>

快速查看示例和 api

License & Copyright

Copyright (c) 2014-2023 飞致云 FIT2CLOUD, All rights reserved.

Licensed under The GNU General Public License version 3 (GPLv3) (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

https://www.gnu.org/licenses/gpl-3.0.html

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an " AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.