Detailed explanation of the organizational structure diagram case of Vue's vue-tree-color component

Detailed explanation of the organizational structure diagram case of Vue's vue-tree-color component

npm

# use npm
npm install vue-tree-color

Install the loader

npm install --save-dev less less-loader

Import Plugins

import Vue from 'vue'
import Vue2OrgTree from 'vue-tree-color'
 
Vue.use(Vue2OrgTree)

start

Because the component has been installed, you can use it directly. In the Vue page, directly use the component tag to dynamically bind the data (the data can be recursive data)

<vue2-org-tree :data="data"/>

Data is placed in the page

In the data data, id is a different ID for each element, label is name, and children is its own subset data.

Arrangement

Just now we saw the default arrangement, but there is also a horizontal arrangement.

# Just add horizontal <vue2-org-tree :data="data" :horizontal="true" />

The effect is as follows

Folding display

Add a property collapsable

<vue2-org-tree :data="data" :horizontal="true" collapsable /> 

How to expand it? You need to add a component with its own method

on-expand

<vue2-org-tree :data="data" :horizontal="true" collapsable @on-expand="onExpand" />

js part

methods: {
    collapse(list) {
        var _this = this
        list.forEach(function(child) {
            if (child.expand) {
                child.expand = false
            }
            child.children && _this.collapse(child.children)
        })
    },
    onExpand(e, data) {
        if ('expand' in data) {
            data.expand = !data.expand
            if (!data.expand && data.children) {
                this.collapse(data.children)
            }
        } else {
            this.$set(data, 'expand', true)
        }
    }
}

The effect is as follows

Click on the node

Add a method on-node-click

<vue2-org-tree :data="data" :horizontal="true" collapsable @on-expand="onExpand" @on-node-click="onNodeHandle" />

js

onNodeHandle(e, data) {
    // e is the node data console.log(e)
    // data is the data rendered on the node console.log(data)
},

Printing Results

Other Features

The component also provides other functions, probably the more commonly used ones are setting node color, moving in and out, etc. I paste the github address in, and those who are interested can learn about it themselves

Click on the link below to view more functions of the component

https://github.com/hukaibaihu/vue-org-tree#readme

This is the end of this article about the detailed explanation of the case of implementing the organizational structure chart of Vue's vue-tree-color component. For more relevant content about implementing the organizational structure chart of Vue's vue-tree-color component, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • How to implement Vue's tree component
  • Vue monitors the change operation of Treeselect selection
  • Vue elementui tree arbitrary level drag function code
  • Vue+Element UI tree control integrates drop-down function menu (tree + dropdown +input)
  • Vue Treeselect tree drop-down box: get the ids and labels of the selected node
  • vue el-tree expands the implementation code of the first node by default

<<:  Brief analysis of mysql scheduled backup tasks

>>:  Linux cut command explained

Recommend

How to customize at and cron scheduled tasks in Linux

There are two types of scheduled tasks in Linux s...

Summary of learning HTML tags and basic elements

1. Elements and tags in HTML <br />An eleme...

How to shut down/restart/start nginx

closure service nginx stop systemctl stop nginx s...

js to achieve a simple lottery function

This article shares the specific code of js to im...

How to install Docker using scripts under Linux Centos

What is the main function of Docker? At present, ...

How to change the CentOS server time to Beijing time

1. I purchased a VPS and CentOS system, and found...

Introduction to JavaScript array deduplication and flattening functions

Table of contents 1. Array flattening (also known...

Detailed tutorial on deploying Jenkins based on docker

0. When I made this document, it was around Decem...

Rounding operation of datetime field in MySQL

Table of contents Preface 1. Background 2. Simula...

Detailed explanation of Vue development Sort component code

Table of contents <template> <ul class=&...

CSS optimization skills self-practice experience

1. Use css sprites. The advantage is that the smal...

Detailed tutorial on installing ElasticSearch 6.x in docker

First, pull the image (or just create a container...