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;
  }
}
相关推荐
小郎君6582 小时前
Vue 多标签页的加载态设计:为什么我没有用 Suspense 实现 PageLoading
vue.js·算法
yilaisai2 小时前
前端开发遇到的一些细节问题整理
vue.js
华玥作者3 小时前
Vue 3 + TypeScript + uni-app 组件库推荐:hy-app(华玥组件库)
vue.js·typescript·uni-app
阿琳a_3 小时前
b-map-viewer:面向 Vue 3 的地图可视化 SDK,从接入到展示再到交互分析
前端·javascript·vue.js·gis·数据可视化·地图
齐 飞4 小时前
VUE2常用语法总结
javascript·vue.js
北城笑笑4 小时前
Vue 106 ,上篇:前端桌面端应用实现方案( Electron 框架详细介绍,Vue + Electron )
前端·javascript·vue.js·python·electron
不磕了还不行5 小时前
用 Vue + Element UI 把元宝搜索的返回值做成“能点开检查的证据卡片”
前端·vue.js·ui
FRing0316 小时前
vue2干货总结2(v-bind、v-for、v-model、指令修饰符、v-bind操作class和style)
开发语言·前端·vue.js·vue2
徐小夕19 小时前
深度剖析 30k star 的编码 Agent DeepSeek-Reasonix:长会话 Token 成本直降 80%
前端·vue.js·github
ruanno_top21 小时前
1 万行表格只渲染 18 行:虚拟滚动让我放弃了三个功能
vue.js