动态breadcrumb
Posted ronle
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了动态breadcrumb相关的知识,希望对你有一定的参考价值。
新建Breadcrumb.vue
<template> <div class="example-container"> <el-breadcrumb separator="/"> <el-breadcrumb-item v-for="(item,index) in breadList" :key="index" :to="{ path: item.path }" >{{item.meta.title}} </el-breadcrumb-item> </el-breadcrumb> </div> </template> <script> export default { name: ‘Breadcrumb‘, data() { return { breadList: [] // 路由集合 }; }, watch: { $route() { this.getBreadcrumb(); } }, methods: { isHome(route) { return route.name === ‘Home‘; }, getBreadcrumb() { let matched = this.$route.matched; //如果不是首页 if (!this.isHome(matched[0])) { matched = [{path: ‘/home‘, meta: {title: ‘首页‘}}].concat(matched); } this.breadList = matched; console.log(this.breadList) } }, created() { this.getBreadcrumb(); } } </script>
路由
const router = new Router({ routes: [ { path: ‘/‘, redirect: ‘/home‘ }, { path: ‘/home‘, name: ‘home‘, component: Home, meta: { title: ‘首页‘ } }, { path: ‘/setting‘, name: "setting", component: () => import(‘./views/setting/Setting.vue‘), redirect: ‘/setting/user‘, meta: { title: ‘系统设置‘ }, children: [{ path: ‘user‘, component: () => import(‘./views/setting/UserMange.vue‘), name: ‘usermanage‘, meta: { title: ‘用户管理‘ } }, { path: ‘message‘, component: () => import(‘./views/setting/MesMange.vue‘), name: ‘mesmanage‘, meta: { title: ‘短信管理‘ } }] }, { path: ‘/example‘, name: ‘example‘, component: Example, meta: { title: ‘综合实例‘ } } ] }); export default router;
然后以子组件形式放到需要的地方
以上是关于动态breadcrumb的主要内容,如果未能解决你的问题,请参考以下文章
bootstrap动态添加面包屑(breadcrumb)及其响应事件的方法