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"背景颜色

相关推荐
前端的日常16 分钟前
以下代码,那一部分运行快
前端
GeGarron17 分钟前
Drawing:专注高效画图,让每一次创作都值得被珍藏
前端
梨子同志17 分钟前
Vue v-model 指令详解
前端·vue.js
杨进军18 分钟前
简易实现 React 页面初次渲染
前端·react.js·前端框架
血舞之境20 分钟前
同名类引发问题:没见过世面导致遇见各种诡异的问题
前端
杨进军20 分钟前
实现 React 多个原生标签子节点渲染
前端·react.js·前端框架
前端的日常20 分钟前
AI 工具中,经常提到的 mcp 是什么,有哪些与前端方向结合的场景?
前端
嘉小华21 分钟前
Android 协程全景式深度解析:第四章 Flow响应式流
android·前端
Tina_晴22 分钟前
【基础篇】Promise初体验+案例分析(上)
前端·javascript·面试
7ayl24 分钟前
闭包
javascript