Vue、Element 路由跳转,左侧菜单高亮显示,页面刷新不会改变当前高亮菜单


el-menu-item index的值,我这里使用了 路由表中route.js中 的 路由name
:default-active="this.$route.name"


如果不理解,可以看下 watch 监听 的 $route

      <el-menu
        class="el-menu-vertical-demo"
        background-color="#324057"
        text-color="#fff"
        active-text-color="#409eff"
        mode="vertical"
        router
        :default-active="this.$route.name"
      >
        <el-menu-item index="home">
          <i class="el-icon-s-home"></i>
          <span slot="title">首页</span>
        </el-menu-item>
        <el-menu-item index="foundlist">
          <i class="el-icon-s-order"></i>
          <span slot="title">信息查询</span>
        </el-menu-item>
        <el-menu-item index="infoshow">
          <i class="el-icon-user-solid"></i>
          <span slot="title">个人信息</span>
        </el-menu-item>
      </el-menu>
export default {
  name: "left-menu",
  data() {
    return {};
  },
  computed: {},
  methods: {},
  watch: {
    $route(to,from){
        // console.log(to)
        console.log(`前往路由:${to.path}`);
    }
  }
};


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM