elementui导航栏刷新选中问题

获取地址栏中的路由,设置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中添加以上代码,这样在渲染之前先把当前的路由设置给导航栏的默认的路由,则刷新也是显示的当前路由的内容,并且导航栏高亮的也是当前路由的那个选项了

原文地址:https://www.cnblogs.com/home-/p/12198059.html