码迷,mamicode.com
首页 > 其他好文 > 详细

动态breadcrumb

时间:2019-11-09 11:41:51      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:return   eth   redirect   rman   template   containe   rip   message   adl   

新建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

标签:return   eth   redirect   rman   template   containe   rip   message   adl   

原文地址:https://www.cnblogs.com/ronle/p/11824756.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!