vue左侧边框点击后让字体高亮

这个效果涉及到一个属性,就是default-active=""

当且仅当标签是el-menu-item的时候,index才会生效,也就是说二级标签才会生效,比如el-submenu就不能生效

复制代码
 <el-aside style="width: 200px;min-height: 100vh;">
        <div
          style="height: 60px;width: 200px;display: flex;align-items: center;justify-content: center;background-color: #ccc;color: white;">
          logo
        </div>
        <el-menu style="border: none;" default-active="/">
          <el-menu-item index="/">
            <template slot="title">
              <i class="el-icon-house"></i><span>系统首页</span>
            </template>
          </el-menu-item>
          <el-menu-item>系统首页</el-menu-item>
          <el-menu-item>系统首页</el-menu-item>
          <el-submenu>
            <template slot="title">
              <i class="el-icon-menu"></i><span>信息管理</span>
            </template>
            <el-menu-item>系统首页</el-menu-item>
            <el-menu-item>系统首页</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

当然此时我们还是死的,只能让第一个变成高亮,那变活如何处理呢!?所以就要用到绑定属性了

<el-menu style="border: none;" :default-active="$route.path">

更改这样代码,加上 :default-active="$route.path",@route.path是当前浏览器正在访问的路由

我们现在可以进行高亮了,但是不能点击啊!怎么做到点击高亮呢?

在添加一个属性,router,这样就可以绑定路由了,也就能做到,点哪个路由就跳转到哪个路由了!

复制代码
 <el-aside style="width: 200px;min-height: 100vh;">
        <div
          style="height: 60px;width: 200px;display: flex;align-items: center;justify-content: center;background-color: #ccc;color: white;">
          logo
        </div>
        <el-menu style="border: none;" router :default-active="$route.path">
          <el-menu-item index="/">
            <template slot="title">
              <i class="el-icon-house"></i><span>系统首页</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/element">element页面</el-menu-item>
          <el-menu-item>系统首页</el-menu-item>
          <el-submenu>
            <template slot="title">
              <i class="el-icon-menu"></i><span>信息管理</span>
            </template>
            <el-menu-item>系统首页</el-menu-item>
            <el-menu-item>系统首页</el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>

我们在补充几个属性,

复制代码
 <el-menu text-color="rgba(255,255,255,0.65)" active-text-color="#fff" background-color="#001529" style="border: none;"router :default-active="$route.path">
          <el-menu-item index="/">
            <template slot="title">
              <i class="el-icon-house"></i><span>系统首页</span>
            </template>
          </el-menu-item>
          <el-menu-item index="/element">element页面</el-menu-item>
          <el-menu-item>系统首页</el-menu-item>
          <el-submenu>
            <template slot="title">
              <i class="el-icon-menu"></i><span>信息管理</span>
            </template>
            <el-menu-item>系统首页</el-menu-item>
            <el-menu-item>系统首页</el-menu-item>
          </el-submenu>
        </el-menu>

text-color="rgba(255,255,255,0.65)":这个就是字体颜色

active-text-color="#fff"这个就是高亮之后的颜色

background-color="#001529"背景颜色

相关推荐
笨蛋不要掉眼泪几秒前
Redis主从复制:原理、配置与实战演示
前端·redis·bootstrap·html
bigdata-rookie4 分钟前
Starrocks 数据模型
java·前端·javascript
白帽子凯哥哥6 分钟前
网络安全Web基础完全指南:从小白到入门安全测试
前端·sql·web安全·信息安全·渗透测试·漏洞
RFCEO12 分钟前
前端编程 课程十四、:CSS核心基础2:选择器优先级 + 伪类选择器(解决冲突+交互效果)
前端·css·交互·css选择器优先级判断规则详解·css important使用·css链接伪类lvha顺序·实现悬浮交互效果
web打印社区14 分钟前
前端实现浏览器预览打印:从原生方案到专业工具
前端·javascript·vue.js·electron
yuezhilangniao17 分钟前
# 告别乱码:用FastAPI特性与Next.js打造类型安全的API通信
javascript·安全·fastapi
jiayong2326 分钟前
Vue2 与 Vue3 生态系统及工程化对比 - 面试宝典
vue.js·面试·职场和发展
徐同保28 分钟前
vue.config.ts配置代理解决跨域,配置开发环境开启source-map
前端·javascript·vue.js
Hexene...1 小时前
【前端Vue】npm install时根据新的状态重新引入实际用到的包,不引入未使用到的
前端·vue.js·npm
2301_780669861 小时前
Vue(入门配置、常用指令)、Ajax、Axios
前端·vue.js·ajax·javaweb