当前位置: 首页 > article >正文

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


http://www.kler.cn/a/573931.html

相关文章:

  • 多线程-线程本地变量ThreadLocal
  • 探秘基带算法:从原理到5G时代的通信变革【十】基带算法应用与对比
  • 前端基础之全局事件总线
  • vue表单已经赋值了,但是还是返回async-validator “xxx is required“提示,弹出验证红字而且不能输入
  • supervisord管理Gunicorn进程,使用Nginx作为反向代理运行flask web项目
  • 代理与 hosts 文件冲突问题解决方案
  • uniapp封装路由管理(兼容Vue2和Vue3)
  • 批量对 Word 优化与压缩,减少 Word 文件大小
  • 通信小贾的西天取经之路:从茫然小白到工业互联网售前
  • Java基础知识大全(含答案,面试基础)
  • FX-结构体
  • FusionInsight MRS云原生数据湖
  • 江科大51单片机笔记【8】LED点阵屏显示图形及动画(下)
  • Hive-优化(参数优化篇)
  • 扩散语言模型:从图像生成到文本创造的范式跃迁
  • 随手记录第十六话 -- Go 语言入门:基础知识与常用框架
  • 计算机网络开发(2)TCP\UDP区别、TCP通信框架、服务端客户端通信实例
  • 每天一个Flutter开发小项目 (13) : 本地数据随心存取 - 构建SQLite ToDo 应用,掌握Flutter本地数据库操作
  • 算法·搜索
  • 《张一鸣,创业心路与算法思维》