vue+elementUI動態(tài)生成面包屑導航教程
更新時間:2019年11月04日 14:55:30 作者:sun shying
今天小編就為大家分享一篇vue+elementUI動態(tài)生成面包屑導航教程,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
效果如下所示:

項目需要動態(tài)生成面包屑導航,并且首頁可以點擊.其余為路徑顯示
<el-menu :unique-opened="true" router :default-active="$route.path" @select="handleSelect">
<div class="user-menu-box" v-for="menu in menus" :key="menu.id">
<el-menu-item v-if="!menu.child" :index="menu.path">
<icon :name="menu.icon" :w="20" :h="20"></icon>
<span slot="title" v-text="menu.name"></span>
</el-menu-item>
<el-submenu v-if="menu.child" :index="menu.path">
<template slot="title">
<icon :name="menu.icon" :w="20" :h="20"></icon>
<span slot="title" v-text="menu.name"></span>
</template>
<el-menu-item-group>
<el-menu-item v-for="subMenu in menu.child" :key="subMenu.id" v-text="subMenu.name"
:index="subMenu.path"></el-menu-item>
</el-menu-item-group>
</el-submenu>
</div>
</el-menu>
上面的代碼是elementUI組件的樣式,根據(jù)項目需要做了修改,搬運的時候根據(jù)項目自己改改
export default {
data () {
return {
activeMenu: '',
indexBreadcrumbs: [],
menus: [{
id: '1',
name: '門戶管理',
icon: 'menhuguanli',
path: '#2',
child: [{
id: '1-1',
name: '輪播圖',
path: '/backstage/protaManage/turns'
}, {
id: '1-2',
name: '基礎數(shù)據(jù)',
path: '/backstage/protaManage/basis'
}, {
id: '1-3',
name: '分類管理',
path: '/backstage/protaManage/classify'
}, {
id: '1-4',
name: '內(nèi)容發(fā)布',
path: '/backstage/protaManage/content'
}]
}, {
id: '2',
name: '我的云盤',
icon: 'yunpan',
path: '/backstage/yunManage'
}, {
id: '3',
name: '管理菜單',
icon: 'shezhi',
path: '/backstage/menusManage'
}, {
id: '4',
name: '編輯板塊',
icon: 'fabuzhongxin',
path: '/backstage/editPlate'
}]
}
},
watch: {
$route () {
this.handChange()
}
},
computed: {
breadcrumbList () {
let breadcrumbs = []
let menuList = this.menus
this.indexBreadcrumbs.map(item => {
for (let i = 0; i < menuList.length; i++) {
if (item === menuList[i].path) {
breadcrumbs.push(menuList[i])
if (menuList[i].child) {
menuList = menuList[i].child
}
break;
}
}
})
return breadcrumbs
}
},
methods: {
handChange () {
this.$emit('hand-change', this.breadcrumbList)
},
handleSelect (index, indexPath) {
this.indexBreadcrumbs = indexPath
}
},
created () {
this.handChange()
}
}
上面的代碼是模擬的數(shù)據(jù),調(diào)用elememtUI的組件導航菜單的中的@select方法,有兩個參數(shù),可以自行打印

然后在computed中計算當前選中的是哪一部分,取到返回值,然后$emit傳給父組件,
<el-breadcrumb separator-class="el-icon-arrow-right">
<el-breadcrumb-item :to="{ path: '/backstage' }">首頁</el-breadcrumb-item>
<el-breadcrumb-item v-for="o in breadcrumbList" :key="o.id">{{o.name}}
</el-breadcrumb-item>
</el-breadcrumb>
父組件中取到子組件傳過來的值后,直接渲染就行了
相關文章
vue查詢數(shù)據(jù)el-table不更新數(shù)據(jù)的解決方案
這篇文章主要介紹了vue查詢數(shù)據(jù)el-table不更新數(shù)據(jù)的問題及解決方案,本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-12-12
vue.js 實現(xiàn)v-model與{{}}指令方法
這篇文章主要介紹了vue.js 實現(xiàn)v-model與{{}}指令方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-10-10

