Element-Plus 面包屑当前项样式以及处理最后一个元素

需求:

通过 面包屑el-breadcrumb组件 实现路由菜单的二次显示,需要当前显示的页面与对应的面包屑菜单联动高亮。

由于该组件给最后一个元素在伪类last-child上设置了样式,所以得对其样式做出调整。

html 复制代码
         <el-breadcrumb separator="/">
            <!-- 首页始终显示 -->
            <el-breadcrumb-item :to="{ path: '/home' }">
              <el-icon><House /></el-icon>
              首页
            </el-breadcrumb-item>

            <!-- 动态面包屑项 -->
            <el-breadcrumb-item
              v-for="item in breadcrumbs"
              :key="item.path"
              :to="{ path: item.path }"
              :class="{ 'current-breadcrumb': item.path === route.path }"
              @click="handleBreadcrumbClick(item)"
            >
              <!-- 菜单图标 -->
              <!-- <el-icon><component :is="route.meta.icon || 'Document'" /></el-icon> -->
              {{ item.title }}
              <el-icon class="breadcrumb-close" @click="removeBreadcrumb(item, $event)">
                <Close />
              </el-icon>
              <!-- 只有非当前页面才显示删除按钮 -->
              <!-- <el-icon
                v-if="item.path !== route.path"
                class="breadcrumb-close"
                @click="removeBreadcrumb(item, $event)"
              >
                <Close />
              </el-icon> -->
            </el-breadcrumb-item>
          </el-breadcrumb>

当前项单独设置类样式:

复制代码
 :class="{ 'current-breadcrumb': item.path === route.path }"
css 复制代码
$breadcrumb-item-color: #409eff;

// 面包屑样式
::v-deep .el-breadcrumb {
  .el-breadcrumb__inner.is-link:hover {
    color: $breadcrumb-item-color;
  }
  /* 自定义当前项样式 */
  .current-breadcrumb .el-breadcrumb__inner {
    color: $breadcrumb-item-color;
    font-weight: bold;
  }

  // 最后一个元素
  .el-breadcrumb__item:last-child .el-breadcrumb__inner {
    color: inherit;
    cursor: pointer;
    font-weight: bold;
    &:hover {
      color: $breadcrumb-item-color;
    }
  }

  .current-breadcrumb:last-child .el-breadcrumb__inner {
    color: $breadcrumb-item-color;
  }
}
相关推荐
1-1=04 小时前
Vue 混入(Mixin)和 2.插件 (Plugins)
前端·vue.js
FRing0316 小时前
vue2干货总结12(loading效果、全局前置导航守卫、搜索历史管理)
开发语言·前端·javascript·vue.js·vue2
徐小夕1 天前
折腾一年,我们正式发布 JitOffice:一款跑在浏览器里的 AI Office
前端·vue.js·github
小码哥0681 天前
短剧平台源码定制交付:批量导入剧集与媒体资源校验流程
前端·vue.js·媒体·短剧小程序·短剧系统·抖音短剧
FRing032 天前
vue3干货总结3(defineOptions(Vue3.3)、defineModel(Vue3.4)、Pinia)
开发语言·前端·vue.js·vue3
tryCbest2 天前
Vue3——第 22 篇:Pinia——新一代状态管理(上)
前端·javascript·vue.js
Lanwarf-前端开发3 天前
Vue3 + Canvas/WebGL 雷达扫描可视化实战:PPI、RHI、VOL、SVOL 四种模式原理与实现
前端·javascript·vue.js·webgl
FRing033 天前
vue3干货总结2(vue3生命周期、父子通信、模版引用、provide和inject)
开发语言·前端·vue.js·vue3
小码哥0683 天前
智慧物业系统源码定制:公告发布范围与住户阅读记录设计
前端·javascript·vue.js·物业管理·物业系统·物业软件
码云社区3 天前
Java在线租房系统源码:VR看房素材、房源图片与内容维护方案
java·vue.js·vr·租房小程序·在线租房·看房租房