vue 导航面包屑

这是一个关于Vue.js中实现面包屑导航组件的示例代码。当路由变化时,通过`watch`监听更新面包屑列表,并根据当前路由匹配到相应的页面标题。同时,定义了特定的样式使得面包屑导航的显示更加符合设计要求,包括颜色、字体大小和布局等。
摘要由CSDN通过智能技术生成
<template>
 <div class="bread">
   <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>
 </div>
</template>
<script>
export default {
  data () {
    return {
      breadList: [] // 路由集合
    }
  },
  watch:{
    $route(){
      this.getBreadcrumb();
    }
  },
  methods: {
    isHome(route) {
      return route.name === "首页";
    },
    getBreadcrumb() {
      let matched = this.$route.matched.filter(item => item.name);
      console.log('eeee1',matched);
      if (!this.isHome(matched[0])) {
        matched = [{ path: "/OnlineEducation/dashboard", meta: { title: "首页" } }].concat(matched);
      }
      this.breadList = matched;
      console.log('wwwww',matched);
    }
  },
   created() {
    this.getBreadcrumb();
  }
}
</script>
<style scoped>
.bread .el-breadcrumb .el-breadcrumb__item:last-child /deep/ .el-breadcrumb__inner{
  color: #1aa972 !important;
}
.bread .el-breadcrumb .el-breadcrumb__item /deep/ .el-breadcrumb__inner{
  color: #999999 !important;
}
.bread  /deep/ .el-breadcrumb{
  display: inline-block;
  display: inline-block;
  height: 48px;
  vertical-align: top;
  line-height: 48px;
  font-size: 20px;
}
.bread /deep/ .is-link{
  font-weight: normal;
}
.bread{
  float:left;
}
</style>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值