使用element-ui的el-menu导航选中后刷新页面保持当前选中

     <el-menu :default-active=‘$route.path‘ :router=‘true‘ :unique-opened=‘true‘ :default-openeds="defaultOpeneds" 
        background-color="#bd1e22" text-color="#fff" active-text-color="#ffd04b">         
        //router当导航激活时允许以index作为路由进行页面的跳转,$route.path当前路由对象的路径,字符串,绝对路径         
        //unique-opened只允许有一个下拉菜单处于打开的状态         
        //使用default-active来实现当前菜单激活的选项
        //default-openeds当前打开的 sub-menu 的 index 的数组
<el-menu-item index=‘/home‘>首页</el-menu-item>
            <el-submenu>
              <template slot="title">
                <i class=‘‘></i><span>导航一</span>
              </template>
              <el-menu-item index=‘/first/page1‘>
                <template slot="title">
                  <i class=‘‘></i><span>选项一</span>
                </template>
              </el-menu-item>
              <el-menu-item index=‘/first/page2‘>
                <template slot="title">
                  <i class=‘‘></i><span>选项二</span>
                </template>
              </el-menu-item>
            </el-submenu>
        </el-menu
>
     mounted(){
            let path = this.$route.path;
            this.navConfig = [
                {index:'1',path:['/system/aa','/system/bb','/system/cc']},
            ];
            let thisNav = this.navConfig.find(item =>{
                return item.path.includes(path);
            });
            this.defaultOpeneds = [thisNav.index];
        }

 

转载于:https://www.cnblogs.com/gxp69/p/11212232.html

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值