Vue2組件tree實(shí)現(xiàn)無限級(jí)樹形菜單
一直打算偷懶使用個(gè)現(xiàn)成的樹組件,但是在github上找了一大圈沒有找到真正滿足應(yīng)用開發(fā)的樹組件,所以沒辦法只能自己寫了一個(gè),開源出來希望可以幫助到需要的人,同時(shí)如果大家覺得好用,我可以順帶騙騙★(希望喜歡的朋友對(duì)我體力的肯定可以點(diǎn)下★ ),由于我也算剛接觸vue,所以難免有所考慮不周的地方,希望大家在issue里面指正。組件重點(diǎn)是父子組件數(shù)據(jù)的共享和狀態(tài)保持,我是利用了下vuex的思路,采用一個(gè)控制倉庫完成。
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: '一級(jí)節(jié)點(diǎn)',
open: true,
checked: false,
parentId: null,
visible: true,
searched: false,
children: [
{
id: 2,
label: '二級(jí)節(jié)點(diǎn)-1',
checked: false,
parentId: 1,
searched: false,
visible: true
},
{
label: '二級(jí)節(jié)點(diǎn)-2',
open: true,
checked: false,
id: 3,
parentId: 1,
visible: true,
searched: false,
children: [
{
id: 4,
parentId: 3,
label: '三級(jí)節(jié)點(diǎn)-1',
visible: true,
searched: false,
checked: false
},
{
id: 5,
label: '三級(jí)節(jié)點(diǎn)-2',
parentId: 3,
searched: false,
visible: true,
checked: false
}
]
},
{
label: '二級(jí)節(jié)點(diǎn)-3',
open: true,
checked: false,
id: 6,
parentId: 1,
visible: true,
searched: false,
children: [
{
id: 7,
parentId: 6,
label: '三級(jí)節(jié)點(diǎn)-4',
checked: false,
searched: false,
visible: true
},
{
id: 8,
label: '三級(jí)節(jié)點(diǎn)-5',
parentId: 6,
checked: false,
searched: false,
visible: true
}
]
}
]
}
]
}
},
components: {Tree}
}
</script>
屬性

options: {
showCheckbox: true, //是否支持多選
search: {
useInitial: true, //是否支持首字母搜索
useEnglish: false, //是否是英文搜索
customFilter: null // 自定義節(jié)點(diǎn)過濾函數(shù)
}
/* 節(jié)點(diǎn)元素 */
{
id: 1, //節(jié)點(diǎn)標(biāo)志
label: '一級(jí)節(jié)點(diǎn)', //節(jié)點(diǎn)名稱
open: true, // 是否打開節(jié)點(diǎn)
checked: false, //是否被選中
parentId: null, //父級(jí)節(jié)點(diǎn)Id
visible: true, //是否可見
searched: false, //是否是搜索值
children: [] //子節(jié)點(diǎn)
}
方法

事件

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- vue Element左側(cè)無限級(jí)菜單實(shí)現(xiàn)
- Vue.js組件tree實(shí)現(xiàn)無限級(jí)樹形菜單
- vue實(shí)現(xiàn)多級(jí)菜單效果
- Vue+Element ui實(shí)現(xiàn)樹形控件右鍵菜單
- vue實(shí)現(xiàn)右鍵彈出菜單
- vue-router+vuex addRoutes實(shí)現(xiàn)路由動(dòng)態(tài)加載及菜單動(dòng)態(tài)加載
- Vue.js 遞歸組件實(shí)現(xiàn)樹形菜單(實(shí)例分享)
- 基于vue.js實(shí)現(xiàn)側(cè)邊菜單欄
- Vue實(shí)現(xiàn)導(dǎo)航欄菜單
- Vue3.0實(shí)現(xiàn)無限級(jí)菜單
相關(guān)文章
最全vue的vue-amap使用高德地圖插件畫多邊形范圍的示例代碼
這篇文章主要介紹了最全vue的vue-amap使用高德地圖插件畫多邊形范圍,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取)
這篇文章主要介紹了vue中異步數(shù)據(jù)獲取方式(確保數(shù)據(jù)被獲取),具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-01-01
vue3中v-for報(bào)錯(cuò)'item'is?of?type'unknown'的
在寫vue3+ts的項(xiàng)目,得到一個(gè)數(shù)組,需要循環(huán)展示,使用v-for循環(huán),寫完之后發(fā)現(xiàn)有個(gè)報(bào)錯(cuò),接下來通過本文給大家介紹vue3中v-for報(bào)錯(cuò)?‘item‘?is?of?type?‘unknown‘的解決方法,感興趣的朋友一起看看吧2023-11-11
Vue-Router基礎(chǔ)學(xué)習(xí)筆記(小結(jié))
這篇文章主要介紹了Vue-Router基礎(chǔ)學(xué)習(xí)筆記(小結(jié)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-10-10
vue?內(nèi)置組件?component?的用法示例詳解
這篇文章主要介紹了vue內(nèi)置組件component的用法,本文給大家介紹了component內(nèi)置組件切換方法,通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-08-08

