Vue2組件tree實現(xiàn)無限級樹形菜單
一直打算偷懶使用個現(xiàn)成的樹組件,但是在github上找了一大圈沒有找到真正滿足應(yīng)用開發(fā)的樹組件,所以沒辦法只能自己寫了一個,開源出來希望可以幫助到需要的人,同時如果大家覺得好用,我可以順帶騙騙★(希望喜歡的朋友對我體力的肯定可以點下★ ),由于我也算剛接觸vue,所以難免有所考慮不周的地方,希望大家在issue里面指正。組件重點是父子組件數(shù)據(jù)的共享和狀態(tài)保持,我是利用了下vuex的思路,采用一個控制倉庫完成。
github 地址 vue-tree
How to run demo
npm install npm run dev
效果圖
示例
<template> <div style="width:300px;"> <tree ref ='tree' :treeData="treeData" :options="options" @node-click='handleNode'/> </div> </template> <script> import Tree from '../components/tree/tree.vue' export default { name: 'test', data () { return { options: { showCheckbox: true, search: { useInitial: true, useEnglish: false, customFilter: null } }, treeData: [ { id: 1, label: '一級節(jié)點', open: true, checked: false, parentId: null, visible: true, searched: false, children: [ { id: 2, label: '二級節(jié)點-1', checked: false, parentId: 1, searched: false, visible: true }, { label: '二級節(jié)點-2', open: true, checked: false, id: 3, parentId: 1, visible: true, searched: false, children: [ { id: 4, parentId: 3, label: '三級節(jié)點-1', visible: true, searched: false, checked: false }, { id: 5, label: '三級節(jié)點-2', parentId: 3, searched: false, visible: true, checked: false } ] }, { label: '二級節(jié)點-3', open: true, checked: false, id: 6, parentId: 1, visible: true, searched: false, children: [ { id: 7, parentId: 6, label: '三級節(jié)點-4', checked: false, searched: false, visible: true }, { id: 8, label: '三級節(jié)點-5', parentId: 6, checked: false, searched: false, visible: true } ] } ] } ] } }, components: {Tree} } </script>
屬性
options: { showCheckbox: true, //是否支持多選 search: { useInitial: true, //是否支持首字母搜索 useEnglish: false, //是否是英文搜索 customFilter: null // 自定義節(jié)點過濾函數(shù) } /* 節(jié)點元素 */ { id: 1, //節(jié)點標(biāo)志 label: '一級節(jié)點', //節(jié)點名稱 open: true, // 是否打開節(jié)點 checked: false, //是否被選中 parentId: null, //父級節(jié)點Id visible: true, //是否可見 searched: false, //是否是搜索值 children: [] //子節(jié)點 }
方法
事件
以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
最全vue的vue-amap使用高德地圖插件畫多邊形范圍的示例代碼
這篇文章主要介紹了最全vue的vue-amap使用高德地圖插件畫多邊形范圍,本文通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取)
這篇文章主要介紹了vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-01-01vue3中v-for報錯'item'is?of?type'unknown'的
在寫vue3+ts的項目,得到一個數(shù)組,需要循環(huán)展示,使用v-for循環(huán),寫完之后發(fā)現(xiàn)有個報錯,接下來通過本文給大家介紹vue3中v-for報錯?‘item‘?is?of?type?‘unknown‘的解決方法,感興趣的朋友一起看看吧2023-11-11Vue-Router基礎(chǔ)學(xué)習(xí)筆記(小結(jié))
這篇文章主要介紹了Vue-Router基礎(chǔ)學(xué)習(xí)筆記(小結(jié)),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10vue?內(nèi)置組件?component?的用法示例詳解
這篇文章主要介紹了vue內(nèi)置組件component的用法,本文給大家介紹了component內(nèi)置組件切換方法,通過實例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-08-08