elementUI导航高亮问题

问题1:当页面设置了标签点击跳转路由的时候,导航栏高亮和当前不一致,还是高亮原来的导航

解决方法:在菜单导航组件中监听路由变化


<el-menu
  :default-active="activeIndex"
  class="el-menu-demo"
  mode="horizontal"
  background-color="#545c64"
  text-color="#fff"
  active-text-color="#ffd04b">
  <el-menu-item index="1">处理中心</el-menu-item>
  <el-submenu index="2">
    <template slot="title">我的工作台</template>
    <el-menu-item index="2-1">选项1</el-menu-item>
    <el-menu-item index="2-2">选项2</el-menu-item>
    <el-menu-item index="2-3">选项3</el-menu-item>
    <el-submenu index="2-4">
      <template slot="title">选项4</template>
      <el-menu-item index="2-4-1">选项1</el-menu-item>
      <el-menu-item index="2-4-2">选项2</el-menu-item>
      <el-menu-item index="2-4-3">选项3</el-menu-item>
    </el-submenu>
  </el-submenu>
  <el-menu-item index="3" disabled>消息中心</el-menu-item>
  <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
</el-menu>

<script>
  export default {
    data() {
      return {
        activeIndex: this.$route.path
      };
    },
    watch: {
      '$route':'getPath'
    },
    methods: {
      getPath(){
        this.activeIndex= this.$route.path;
      }
    }
  }
</script>

问题2:页面强制刷新,按F5时,页面如果没有好好设置的话,导航栏默认叠起来,而且无高亮显示;刷新后导航栏显示和之前不一致

mounted:{
    let href = window.location.href;
    this.activeIndex=href.split('/#')[1];
}

猜你喜欢

转载自blog.csdn.net/qq_36711388/article/details/88982475
今日推荐