路由切换之后默认高亮/刷新页面后导航栏路由与页面不一致问题终极方案

路由切换默认高亮

请注意,一定要保证你:default-active 路由的值 和你路由path的值相同

下面我列出方法,利用sessionStorage来解决这个问题

这是一些相关的值

:default-active="activePath"
activePath: "",

绑定点击对象

      <el-menu-item
        v-for="item in list"
        :key="item.id"
        :index="item.path"
        @click="getStore(item.path)"
      >

methods 和created中定义方法

  methods: {
    getStore(activePath) {
      window.sessionStorage.setItem('activePath',activePath)
      this.activePath = activePath
    },
  },
  created() {
        this.activePath = window.sessionStorage.getItem('activePath')
  },

问题解决


版权声明:本文为m0_56986233原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。