Menu.vue 2.56 KB
<template>
  <div class="Navs">
    <el-menu
      :default-active="activeMenu"
      class="el-menu-vertical-demo"
      :collapse="true"
      router
    >
      <el-menu-item index="/homePage">
        <i class="el-icon-menu"></i>
        <span>首页</span>
        <!-- <span slot="title">首页</span> -->
      </el-menu-item>
      <div v-for="v in navList" :key="v.id">
        <template v-if="v.children && v.children.length">
          <el-submenu :index="v.path">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span slot="title">{{ v.fullName }}</span>
            </template>
            <el-menu-item-group>
              <span slot="title">分组一</span>
              <el-menu-item
                :index="item.path"
                v-for="item in v.children"
                :key="item.id"
                >{{ item.fullName }}</el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="v.path">
            <i class="el-icon-menu"></i>
            <span>{{ v.fullName }}</span>
          </el-menu-item>
        </template>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  name: "Navs",

  data() {
    return {
      navList: "",
    };
  },
  mounted() {
    this.navList = this.$store.state.user.menuList;
  },
  computed: {
    // 默认激活的菜单
    activeMenu() {
      console.log("activeMenu", this.$route.path);
      return this.$route.path;
    },
  },
};
</script>
<style scoped lang="scss">
.Navs {
  .el-menu-vertical-demo:not(.el-menu--collapse) {
    width: 200px;
    min-height: 400px;
  }
  :deep(.el-menu--collapse) {
    width: 100%;
  }
  .el-menu-item {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    line-height: 30px;
    color: #fff;
    &.is-active {
      color: #1890ff;
      background-color: #dfdada34;
    }
    span {
      height: 30px;
      width: 100%;
      overflow: unset;
      visibility: unset;
    }
    &:hover {
      background-color: #dfdada56;
    }
  }
  :deep(.el-menu) {
    background-color: transparent;
    border-right: unset;
    .el-submenu__title {
      display: flex;
      flex-direction: column;
      align-items: center;
      line-height: 30px;
      justify-content: center;
      color: #fff;
      &:hover {
        background-color: #dfdada56;
      }
    }
    i {
      color: #fff;
    }
    .el-submenu__icon-arrow.el-icon-arrow-right {
      display: none;
    }
  }
}
</style>