Vue之vue-tree-color組件實現(xiàn)組織架構(gòu)圖案例詳解
npm
# use npm npm install vue-tree-color
安裝loader
npm install --save-dev less less-loader
Import Plugins
import Vue from 'vue' import Vue2OrgTree from 'vue-tree-color' Vue.use(Vue2OrgTree)
開始
因為已經(jīng)安裝過了組件,所以可以直接使用,在vue頁面中,直接使用組件標(biāo)簽,動態(tài)綁定data數(shù)據(jù)(data數(shù)據(jù)為遞歸數(shù)據(jù)即可)
<vue2-org-tree :data="data"/>
data數(shù)據(jù)放入頁面中
其中,data數(shù)據(jù)中,id 每個元素不同的ID ,label為name, children為自己的子集數(shù)據(jù)
排列方式
剛才我們看到是默認(rèn)排列方式,其實還有一種水平排列方式
# 只需要加上 horizontal 即可 <vue2-org-tree :data="data" :horizontal="true" />
效果如下
折疊展示
添加一個屬性 collapsable
<vue2-org-tree :data="data" :horizontal="true" collapsable />
怎么展開呢,需要加一個組件自帶方法
on-expand
<vue2-org-tree :data="data" :horizontal="true" collapsable @on-expand="onExpand" />
js部分
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) } } }
效果如下
點擊節(jié)點
添加一個方法 on-node-click
<vue2-org-tree :data="data" :horizontal="true" collapsable @on-expand="onExpand" @on-node-click="onNodeHandle" />
js
onNodeHandle(e, data) { // e是節(jié)點數(shù)據(jù) console.log(e) // data是渲染在節(jié)點上的數(shù)據(jù) console.log(data) },
打印結(jié)果
其他功能
組件還提供了其他功能,大概比較常用的還有,設(shè)置 節(jié)點 顏色 ,移入移出功能,等等,我把github地址粘貼進(jìn)來,有興趣的可以自己了解
點擊下方鏈基即可查看組件更多功能
https://github.com/hukaibaihu/vue-org-tree#readme
到此這篇關(guān)于Vue之vue-tree-color組件實現(xiàn)組織架構(gòu)圖案例詳解的文章就介紹到這了,更多相關(guān)Vue之vue-tree-color組件實現(xiàn)組織架構(gòu)圖內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
JavaScript仿小米商城官網(wǎng)完整頁面實現(xiàn)流程
只能看不能玩的靜態(tài)頁面早就看夠了吧,今天我們來做一個相對完整的動態(tài)網(wǎng)站,用Javascript來實現(xiàn)模仿小米的官網(wǎng)商城,感興趣的朋友快來看看吧2021-11-11IE6、IE7中setAttribute不支持class/for/rowspan/colspan等屬性
IE6、IE7中setAttribute不支持class/for/rowspan/colspan等屬性的說明,需要的朋友可以參考下。2011-08-08