使用$route制作面包屑

使用$route制作面包屑

1. 在router中加上meta属性
{
    path: '/thematicDiscussion',
    name: 'thematicDiscussion',
    redirect: '/thematicDiscussion/home',
    component: layout,
    // component: thematicDiscussion,
    meta: { title: '专题讨论', icon: 'el-icon-location' },
    children: [
      {
        path: 'home',
        name: 'thematicHome',
        meta: { title: '首页' },
        component: thematicList,
      },
2. 在watch中监测$route
watch: {
    $route(route) {
      // if you go to the redirect page, do not update the breadcrumbs
      if (route.path.startsWith('/redirect/')) {
        return
      }
      this.getBreadcrumb()
    }
  },
  created() {
    this.getBreadcrumb()
  },
3.用this.$route.matched获取当前的route信息, 最后获取到this.levelList就能做面包屑了
getBreadcrumb() {
      // only show routes with meta.title
      let matched = this.$route.matched.filter(item => item.meta && item.meta.title)
      const first = matched[0]
      console.log('matched[0]', this.$route.matched);
      this.levelList = matched.filter(item => item.meta && item.meta.title && item.meta.breadcrumb !== false)
    },
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值