使用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];
        }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM