使用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

你可能感兴趣的:(使用element-ui的el-menu导航选中后刷新页面保持当前选中)