VUE+elementui面包屑實(shí)現(xiàn)動(dòng)態(tài)路由詳解
我的路由:
const routerMap = [ { path: '/', redirect: 'dashboard', component: Layout, name:'Dashboard', children: [ { path: 'dashboard', component: () => import('@/view/dashboard'), name: 'Dashboard', meta: { title: 'dashboard', icon: 'dashboard', noCache: true } } ] },{ path:'/test', component:Layout, redirect: '/test/index', name:'Test', meta:{title:'test',icon:'lock'}, children:[ { path:'index', component:()=>import('@/view/test'), name:'test', meta:{title:'test', icon: 'example', noCache: true } },{ path:'example', component:()=>import('@/view/test/example'), name:'example', meta:{title:'example',icon:'404'} } ] } ]
面包屑代碼:
<template> <div class="navbar clearfix"> <el-breadcrumb class="breadcrumb-container" separator-class="el-icon-arrow-right"> <el-breadcrumb-item v-for="item in levelList":key="item.path" :to="item.path">{{item.meta.title}}</el-breadcrumb-item> </el-breadcrumb> </div> </template> <script> export default { name: 'Navbar', data() { return { levelList: [] } }, watch: { $route() { this.getBreadcrumb() } }, created(){ this.getBreadcrumb() }, methods:{ getBreadcrumb() { let matched = this.$route.matched.filter(item => item.name) const first = matched[0]; if (first && first.name.trim().toLocaleLowerCase() !== 'Dashboard'.toLocaleLowerCase()) { matched = [{ path: '/dashboard', meta: { title: 'dashboard' }}].concat(matched) } this.levelList = matched } } } </script>
原理:通過(guò)監(jiān)聽(tīng)當(dāng)前路由的變化,動(dòng)態(tài)更新面包屑的內(nèi)容。
以上這篇VUE+elementui面包屑實(shí)現(xiàn)動(dòng)態(tài)路由詳解就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
vue中的路由傳值與重調(diào)本路由改變參數(shù)
這篇文章主要介紹了vue中的路由傳值與重調(diào)本路由改變參數(shù)方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-09-09關(guān)于vue.js中實(shí)現(xiàn)方法內(nèi)某些代碼延時(shí)執(zhí)行
今天小編就為大家分享一篇關(guān)于vue.js中實(shí)現(xiàn)方法內(nèi)某些代碼延時(shí)執(zhí)行,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11vue根據(jù)權(quán)限動(dòng)態(tài)渲染按鈕、組件等的函數(shù)式組件實(shí)現(xiàn)
這篇文章主要介紹了vue根據(jù)權(quán)限動(dòng)態(tài)渲染按鈕、組件等的函數(shù)式組件實(shí)現(xiàn)方式,具有很好的參考價(jià)值,希望杜大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-11-11vue實(shí)現(xiàn)列表滾動(dòng)的過(guò)渡動(dòng)畫(huà)
這篇文章主要為大家詳細(xì)介紹了vue實(shí)現(xiàn)列表滾動(dòng)的過(guò)渡動(dòng)畫(huà),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-06-06Vue關(guān)于數(shù)據(jù)綁定出錯(cuò)解決辦法
這篇文章主要介紹了Vue關(guān)于數(shù)據(jù)綁定出錯(cuò)解決辦法的相關(guān)資料,需要的朋友可以參考下2017-05-05Vue+element使用row-class-name修改el-table某一行解決背景色無(wú)效的方法
本文主要介紹了Vue+element使用row-class-name修改el-table某一行解決背景色無(wú)效的方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-01-01