npm# use npm npm install vue-tree-color Install the loadernpm install --save-dev less less-loader Import Pluginsimport Vue from 'vue' import Vue2OrgTree from 'vue-tree-color' Vue.use(Vue2OrgTree) startBecause 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. ArrangementJust 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 displayAdd 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 nodeAdd 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 FeaturesThe 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:
|
<<: Brief analysis of mysql scheduled backup tasks
>>: Linux cut command explained
There are two types of scheduled tasks in Linux s...
When we add an svg image to display, react prompt...
1. Elements and tags in HTML <br />An eleme...
Image tag : <img> To insert an image into a ...
closure service nginx stop systemctl stop nginx s...
Required effect: After clicking to send the verif...
This article shares the specific code of js to im...
What is the main function of Docker? At present, ...
1. I purchased a VPS and CentOS system, and found...
Table of contents 1. Array flattening (also known...
0. When I made this document, it was around Decem...
Table of contents Preface 1. Background 2. Simula...
Table of contents <template> <ul class=&...
1. Use css sprites. The advantage is that the smal...
First, pull the image (or just create a container...