el-menu菜单下划线解决办法

本文详细描述了在Vue项目中,如何通过修改`router-link`和CSS样式来移除`<el-menu>`组件中激活链接的下划线,并提供了解决方案。关键点包括使用Scoped Styles避免全局影响,以及针对`<router-link>`的特定处理。

现象说明:

代码实现:

                               <router-link to="/index">      // 关键节点,使用router-link,一旦使用了这个链接,那么就会出现上边的下划线了。
                                    <el-menu-item index="0">
                                        <template slot="title">
                                        <i class="el-icon-s-home"></i>
                                        <span>首页</span>
                                        </template>
                                    </el-menu-item>
                                </router-link>

                                <el-submenu :index="menu.name" v-for="menu in menuList">
                                    <template slot="title">
                                        <i :class="menu.icon"></i>
                                        <span>{{ menu.title }}</span>
                                    </template>

                                    <router-link :to="item.path" v-for="item in menu.children">  // 关键节点,使用router-link,一旦使用了这个链接,那么就会出现上边的下划线了。
                                        <el-menu-item :index = "item.name" @click="selectMenu(item)">
                                            <template slot="title">
                                             <i :class="menu.icon"></i>
                                            <span>{{ item.title }}</span>
                                            </template></el-menu-item>
                                    </router-link>
                                </el-submenu>

解决方法:

 <style scoped>
 .el-menu{
     height:100% 
 }
 .router-link-active{
    text-decoration: none;
  }
a{
    text-decoration: none;
}
 </style>

解决效果:

.el-menu--horizontal .el-menu-item.is-active, .el-submenu.is-active .el-submenu__title { background: #7eb63b !important; /* 设置激活背景颜色 */ color: white !important; /* 设置激活文本颜色 */ } /* 悬停状态的样式 */ .el-menu-item:hover, .el-submenu__title:hover { background: rgb(41, 41, 41); /* 设置悬停背景颜色 */ } /* 确保二级菜单头部在激活时有背景色 */ .el-submenu__title.is-active { background: #7eb63b !important; /* 设置激活背景颜色 */ color: white !important; /* 设置激活文本颜色 */ } // 背景透明 .el-menu-demo { background: transparent; } // 去除自带的底部border .el-menu.el-menu--horizontal { border: none; } // 更改鼠标划过背景色字体色及borer显示 .el-menu--horizontal ::v-deep.el-menu-item:not(.is-disabled):hover { background:transparent !important; color: #fff; border-bottom: 1px solid #fff !important; } /* 全局样式(无scoped) */ .el-menu--horizontal .el-submenu .el-menu-item.is-active { background-color: #ffd04b !important; } /* 组件内样式(带scoped时需穿透) */ ::v-deep .el-menu--horizontal .el-submenu .el-menu-item.is-active { background-color: #ffd04b; }/* 一级菜单项和二级菜单项的公共样式 */ .el-menu-item, .el-submenu__title { width: auto; /* 自适应宽度 */ min-width: 150px; /* 设置最小宽度,防止过窄 */ text-align: center; /* 确保文本居中 */ display: flex; align-items: center; justify-content: center; height: 100%; } /* 二级菜单的样式 */ .el-submenu .el-menu { width: 100%; /* 确保子菜单宽度与父菜单项一致 */ position: absolute; /* 确保子菜单绝对定位 */ left: 0; /* 确保子菜单与父菜单项对齐 */ min-width: 100%; /* 确保子菜单宽度至少与父菜单项一致 */ } /* 水平菜单的一级菜单项和二级菜单项的公共样式 */ .el-menu--horizontal > .el-menu-item, .el-menu--horizontal > .el-submenu { display: flex; align-items: center; justify-content: center; height: 100%; min-width: 150px; /* 设置最小宽度,防止过窄 */ flex: 1; } <el-menu background-color="#333" text-color="#fff" :default-active="activeIndex" class="el-menu-demo" mode="horizontal" router style="list-style: square !important; height: 100%;" >请看我给你的代码
03-24
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值