獲取地址欄中的路由,設置elementui中的導航欄選中狀態
<el-menu :default-active="activerouter" class="el-menu-vertical-demo" background-color="#13141f" text-color="#fff" active-text-color="#fff" router style="height:100%" >
data
activerouter: ""
mounted() { // 頁面手動刷新指定路由 //獲取地址欄中的路由,設置elementui中的導航欄選中狀態 let defaultMenu = window.location.hash.substr( window.location.hash.indexOf("/") ); this.activerouter = defaultMenu; }
在mounted中添加以上代碼,這樣在渲染之前先把當前的路由設置給導航欄的默認的路由,則刷新也是顯示的當前路由的內容,並且導航欄高亮的也是當前路由的那個選項了