使用element-ui的el-menu導(dǎo)航選中后刷新頁(yè)面保持當(dāng)前選中狀態(tài)
具體代碼如下所示:
<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當(dāng)導(dǎo)航激活時(shí)允許以index作為路由進(jìn)行頁(yè)面的跳轉(zhuǎn),$route.path當(dāng)前路由對(duì)象的路徑,字符串,絕對(duì)路徑 //unique-opened只允許有一個(gè)下拉菜單處于打開(kāi)的狀態(tài) //使用default-active來(lái)實(shí)現(xiàn)當(dāng)前菜單激活的選項(xiàng) //default-openeds當(dāng)前打開(kāi)的 sub-menu 的 index 的數(shù)組 <el-menu-item index=‘/home‘>首頁(yè)</el-menu-item> <el-submenu> <template slot="title"> <i class=‘‘></i><span>導(dǎo)航一</span> </template> <el-menu-item index=‘/first/page1‘> <template slot="title"> <i class=‘‘></i><span>選項(xiàng)一</span> </template> </el-menu-item> <el-menu-item index=‘/first/page2‘> <template slot="title"> <i class=‘‘></i><span>選項(xiàng)二</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]; }
ps:下面看下vue Element-ui el-menu 左側(cè)導(dǎo)航條
<template> <!--實(shí)現(xiàn)左側(cè)導(dǎo)航條動(dòng)態(tài)渲染(三級(jí))--> <el-menu class="el-menu-vertical-demo" @open="handleOpen" @close="handleClose" :collapse="isCollapse" router unique-opened background-color="#545c64" text-color="#fff" active-text-color="#ffd04b"> <el-menu-item index="/home/main"> <i class="el-icon-document"></i> <span slot="title">首頁(yè)</span> </el-menu-item> <el-submenu v-for="(item,index) in content" :key="item.id" :data="item" v-if="item.children.length>0&&item.level==1" :index="item.linkname"> <template slot="title"> <i class="el-icon-location"></i> <span slot="title">{{item.linkname}}</span> </template> <el-submenu v-for="(child,seq) in item.children" :data="child" v-if="item.id==child.parentid&&child.children.length>0&&child.level==2" :key="child.id" :index="child.linkname"> <span slot="title">{{child.linkname}}</span> <el-menu-item v-for="three in child.children" :data="three" v-if="child.id==three.parentid&&child.children.length!=0&&three.level==3" :key="three.id" :index="three.link"> <span slot="title">{{three.linkname}}</span> </el-menu-item> </el-submenu> <!--2無(wú)子級(jí)顯示--> <el-menu-item v-for="(child,seq) in item.children" :data="child" v-if="item.id==child.parentid&&child.children.length==0&&child.level==2" :key="child.id" :index="child.link"> <span slot="title">{{child.linkname}}</span> </el-menu-item> </el-submenu> <!--1無(wú)子級(jí)顯示且不支持點(diǎn)擊事件--> <el-menu-item v-for="(item,index) in content" :key="item.id" :data="item" v-if="item.children.length==0&&item.level==1" :index="item.linkname" :disabled="item.children.length==0 ? true : false "> <i class="el-icon-setting"></i> <span slot="title">{{item.linkname}}</span> </el-menu-item> </el-menu> </div> </template> <script> import axios from "axios"; import $ from 'jquery'; export default { data() { return { content: [], isCollapse: false, defaultProps: { children: 'children', label: 'linkname' } }; }, mounted(){ var _self = this; axios.get('https://5b90a18b3ef10a001445d08e.mockapi.io/api/v1/resources') .then(function (response) { _self.content = returnZhData(response.data); }) .catch(function (error) { console.log(error); }); }, methods: { handleOpen(key, keyPath) { console.log(key, keyPath); }, handleClose(key, keyPath) { console.log(key, keyPath); }, handleNodeClick(content) { console.log(content); } } } function returnZhData(data){ var arrone=[]; $.each(data, function(index,one) { if(one['level'] == 1){ arrone.push(one); var arrtwo=[]; $.each(data, function(index,two) { if(two['level'] == 2 && two['parentid']==one['id']){ arrtwo.push(two); var arrthree=[]; $.each(data, function(index,three) { if(three['level'] == 3 && three['parentid']==two['id']){ arrthree.push(three); } }); two.children=arrthree; } }); one.children = arrtwo; } }); return arrone; } </script> <style> .el-menu-vertical-demo:not(.el-menu--collapse) { width: auto; min-height: 400px; } </style>
總結(jié)
以上所述是小編給大家介紹的使用element-ui的el-menu導(dǎo)航選中后刷新頁(yè)面保持當(dāng)前選中,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺(jué)得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
jquery實(shí)現(xiàn)一個(gè)全局計(jì)時(shí)器(商城可用)
這篇文章主要介紹了jquery實(shí)現(xiàn)一個(gè)全局計(jì)時(shí)器,商城一類(lèi)都可以使用2017-06-06jQuery基于cookie實(shí)現(xiàn)換膚功能實(shí)例
這篇文章主要介紹了jQuery基于cookie實(shí)現(xiàn)換膚功能,結(jié)合具體實(shí)例形式分析了jQuery使用cookie記錄與讀取用戶(hù)信息實(shí)現(xiàn)頁(yè)面樣式的操作方法,需要的朋友可以參考下2017-10-10jQuery中setTimeout的幾種使用方法小結(jié)
jQuery 中 setTimeout/setInterval 不能像在原生態(tài) javascript 中那樣使用, 否則會(huì)報(bào)錯(cuò).2013-04-04JQueryEasyUI datagrid框架的進(jìn)階使用
本篇文章小編為大家介紹JQueryEasyUI datagrid框架的基本使用,有需要的朋友可以參考一下2013-04-04當(dāng)jQuery1.7遇上focus方法的問(wèn)題
如果一定要用最高版本的jQuery,最省事的辦法莫過(guò)于在寫(xiě)xxx.focus()時(shí),加一個(gè)try/catch,變成try{xxx.focus();}catch(e){}2014-01-01etmvc+jQuery EasyUI+combobox多值操作實(shí)現(xiàn)角色授權(quán)實(shí)例
本篇文章主要介紹了etmvc+jQuery EasyUI+combobox多值操作實(shí)現(xiàn)角色授權(quán),實(shí)現(xiàn)對(duì)角色role進(jìn)行授權(quán)操作,有需要的可以了解一下。2016-11-11jQuery組件easyui對(duì)話(huà)框?qū)崿F(xiàn)代碼
這篇文章主要為大家詳細(xì)介紹了jQuery組件easyui對(duì)話(huà)框?qū)崿F(xiàn)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08jQuery訪(fǎng)問(wèn)json文件中數(shù)據(jù)的方法示例
這篇文章主要介紹了jQuery訪(fǎng)問(wèn)json文件中數(shù)據(jù)的方法,結(jié)合實(shí)力形式分析了jQuery事件響應(yīng)及json文件的加載、讀取、遍歷等相關(guān)操作技巧,需要的朋友可以參考下2019-01-01