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

@ba1q1/vue-easy-tree

v1.1.0

Published

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

Downloads

8

Readme

vue-easy-tree

介绍

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

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

v1.0 功能列表 npm

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

特点

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

安装

npm install @ba1q1/vue-easy-tree

yarn add @ba1q1/vue-easy-tree

引入

全局引入

main.js 文件中引入:

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

Vue.use(VueEasyTree)

组件引入

在组件中引入:

import VueEasyTree from "@ba1q1/vue-easy-tree";
// 样式文件,可以根据需要自定义样式或主题
import "@ba1q1/vue-easy-tree/src/assets/index.scss"

export default {
  components: {
    VueEasyTree
  }
}

使用:

:warning: 在使用虚拟滚动时,必须设置 node-key

<template>
  <div class="ve-tree" style="height:calc(100vh - 20px)">
  <!-- 不使用虚拟滚动时只需去掉height参数即可 -->
    <vue-easy-tree
      ref="veTree"
      node-key="id"
      height="calc(100vh - 20px)"
      :data="treeData"
      :props="props"
    ></vue-easy-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: "~@ba1q1/vue-easy-tree/src/assets/fonts";

@import "@ba1q1/vue-easy-tree/src/assets/index.scss";

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

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

import Vue from 'vue'
import VueEasyTree from "@ba1q1/vue-easy-tree";
import "./css/ve-tree-var.scss"

Vue.use(VueEasyTree)

其它属性和方法

来自element-ui 官方文档 需要使用虚拟滚动时,增加 height 属性即可,如:

<vue-easy-tree :data="data" height="calc(100vh - 20px)" :props="defaultProps" @node-click="handleNodeClick"></vue-easy-tree>

<!-- 默认开启固定高度模式,子item动态高度模式需要手动开启,如下:isDynamic为true开启,配合minItemSize设置第一次渲染时的子item最小高度 -->
<vue-easy-tree :data="data" height="calc(100vh - 20px)" :props="defaultProps" @node-click="handleNodeClick" :minItemSize="50" isDynamic></vue-easy-tree>

快速查看示例和api

License

MIT