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