Giter Club home page Giter Club logo

vue-easy-tree's Introduction

npm vue2 last commit NPM downloads license

vue-easy-tree

English | 中文

Introduction

A tree component based on vue2.x that supports a small amount of data or a large amount of data, multiple functions, and virtual scrolling.

Based on the tree style and function extracted from element-ui(License:MIT), combined with vue-virtual-scroller(License:MIT) tree component.

v1.0 Feature List npm

  • Large data volume supports virtual scrolling
  • Display of basic tree data
  • Support checkbox selection
  • Support lazy loading
  • Expanded by default and selected by default
  • Disable node
  • Select nodes and obtain selected node information in a variety of ways
  • Support custom node content
  • Support node filtering
  • Support accordion mode under non-virtual scrolling
  • Support node drag and drop when non-lazy loading

Features

  • Support virtual scrolling
  • Not only supports tree-shaped data display with large amounts of data, but also supports data manipulation and modification

Install

npm install @wchbrad/vue-easy-tree

or

yarn add @wchbrad/vue-easy-tree

Mount

mount with global

Import in the main.js file:

import Vue from "vue";
import VueEasyTree from "@wchbrad/vue-easy-tree";
// Style file, you can customize the style or theme according to your needs
import "@wchbrad/vue-easy-tree/src/assets/index.scss"

Vue.use(VueEasyTree)

mount with component

Import in the component:

import VueEasyTree from "@wchbrad/vue-easy-tree";
// Style file, you can customize the style or theme according to your needs
import "@wchbrad/vue-easy-tree/src/assets/index.scss"

export default {
  components: {
    VueEasyTree
  }
}

Usage:

⚠️ When using virtual scrolling, node-key must be set

<template>
  <div class="ve-tree" style="height:calc(100vh - 20px)">
  <!-- Just remove the height parameter when not using virtual scrolling -->
    <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>

Change SCSS variables in the project

By creating a new style file, such as: ve-tree-var.scss, write the following content:

/* Change theme color variable */
$--color-primary: #ea5404;

/* Change the icon font path variable, required */
$--font-path: "~@wchbrad/vue-easy-tree/src/assets/fonts";

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

⚠️ It should be noted that it is necessary to override the font path variable, and assign it to the relative path where the icon icon in @wchbrad/vue-easy-tree is located.

Then directly import the above style files in main.js

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

Vue.use(VueEasyTree)

Other properties and methods

From element-ui official document
When you need to use virtual scrolling, just add the height property, such as:

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

Quick view of examples and api

License

MIT

vue-easy-tree's People

Contributors

qishibo avatar wchbrad avatar zertu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vue-easy-tree's Issues

开启虚拟滚动时,懒加载需要增加node-key么?

开启虚拟滚动时,懒加载我这边测试有问题

<template>
  <div class="ve-tree" style="height:calc(100vh - 20px)">
    <vue-easy-tree
      ref="veTree"
      node-key="id"
      height="calc(100vh - 20px)"
      :props="props"
      lazy
      :load="loadNode"
    ></vue-easy-tree>
  </div>
</template>

<script>
export default {
  data() {
    return {
      props: {
        label: "name",
        children: "children"
      },
      treeData: []
    };
  },
  created() {

  },
  methods: {
    loadNode(node, resolve) {
      if (node.level === 0) {
        return resolve([{ name: 'region' }]);
      }
      if (node.level > 1) return resolve([]);

      this.getChildrenData(resolve)      
    },
    getChildrenData(resolve) {
      setTimeout(() => {
        const data = [
          {
            name: Math.random(),
          },
          {
            name: Math.random(),
          },
          {
            name: Math.random(),
          },
          {
            name: Math.random(),
          },                     
        ]

        resolve(data)
      }, 1000)
    }    
  }
};
</script>

<style>
</style>

image

从隐藏到显示,虚拟列表不生效

我把vue-easy-tree和el-select组合了一下,做成了树型的下拉框组件,展开下拉框的时候虚拟列表不生效,布局也不正确,要不要考虑解决一下这种从隐藏到显示的问题,例如可以向外暴露一个重新渲染的函数

在出现滚动条后,向上滚动过程会突然全部收起所有的节点

  • 项目描述: 我原来使用el-tree的updateKeyChildren来实现类似点击某节点后再动态加载该节点下的数据,并没有采用el-tree组件的lazy+load的形式去懒加载,后来某些节点下面会有上万条数据导致页面卡死后,尝试使用vue-easy-tree的虚拟滚动来解决问题

  • 问题描述: 再直接替换el-tree为vue-easy-tree时,没有任何报错,每个节点都能顺利展开,尤其是上万条节点也能顺利显示,但是当出现滚动条时,只要向上滚动至接近顶部时,所有展开的节点会全部收起。

不能使用height:​ 100%定义高度

提示报错:Error in v-on handler: "Error: Rendered items limit reached"

It seems the scroller element isn't scrolling, so it tries to render all the items at once. Scroller: <div class=​"vue-recycle-scroller ready direction-vertical" style=​"height:​ 100%;​ overflow-y:​ auto;​ scroll-behavior:​ smooth;​">​…​​
vue-virtual-scroller.esm.js?e508:619 Make sure the scroller has a fixed height (or width) and 'overflow-y' (or 'overflow-x') set to 'auto' so it can scroll correctly and only render the items visible in the scroll viewport.

发现子节点超过2000多好像就会报这样的错,然后数据就只会加载一半

滚动到底部渲染速度慢

正要实现虚拟滚动,就找到你这个了,赞
不过跑了demo,发现最顶端的渲染延迟可忽略,但几万节点时,最底端的节点渲染会有延迟,卡顿了几下,是因为上面节点太多,累计计算的原因么【展开节点2w】
Peek 2022-04-05 11-03

支持展开收起动画

于 Element-ui 的组件相比,缺少了展开/收起的动画。

缺少动画也就缺少了一些自然的感觉

根据data中的属性,隐藏checkbox

大佬,我想实现根据数据中的某个属性,决定是否展示checkbox,怎么弄啊。比如图片中,不想要通道的checkbo展示出来。这个树的层级不定,可能会嵌套很深。
image

非常好

谢谢大佬~非常感谢,不管样式还是功能都很全,

支持 props.children 为函数吗?

支持 props.children 为函数吗?
在某些层级不想让其有下层级,想通过改变 props.children 实现,比如 props.children(data, node) 让开发者来判断是否有下层级?

不同的节点可以不一样的高吗?

比如一个树结构,有些节点需要高度大些,有些节点需要高度小些,有属性可以进行这样的调整吗 ?发现有个item-size是可以调节高度的,但他是调整所有节点高度,可以一些特殊的节点去专门调节他的高度吗;如果使用scoped slot的话 只能改样式,但涉及到高度时,超出的部分并不能给高撑开

不兼容低版本Vue

提示item跟active is not defined,查看原因发现不兼容vue2.5.17,能否兼容一下

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.