如何优雅的封装element侧边栏(复制即用)

鼠标悬浮从右侧弹出子菜单 :

<template>
  <div>
    <el-menu
      @select="handleSelect"
      :default-active="currentIndexLight"
      class="el-menu-vertical-demo"
      @open="handleOpen"
      @close="handleClose"
      collapse
      :popper-append-to-body="true"
    >
      <div v-for="item in tabList" :key="item.pathh">
        <!-- 没有子菜单 -->
        <template v-if="!item.children">
          <el-menu-item :index="item.pathh">
<!--图标-->
            <!-- <i class="el-icon-menu"></i> -->
            {{ item.title }}
          </el-menu-item>
        </template>
        <!-- 有子菜单 -->
        <el-submenu v-else :index="item.pathh">
          <template slot="title">
            <!-- <i class="el-icon-menu"></i> -->
            {{ item.title }}
          </template>

          <template v-for="child in item.children">
            <!-- 递归循环 -->
            <sidebar-item
              v-if="child.children && child.children.length > 0"
              :item="child"
              :key="child.pathh"
            />
            <el-menu-item v-else :key="child.pathh" :index="child.pathh">
              <!-- <i class="el-icon-location"></i> -->
              {{ child.title }}
            </el-menu-item>
          </template>
        </el-submenu>
      </div>
    </el-menu>
  </div>
</template>

<script>
export default {
  props: {
    tabList: Array,
    currentIndexLight: String,
  },
  methods: {
    handleSelect(e, x) {
      this.$emit('handleSelect',e,x)
    },
    handleOpen(key, keyPath) {
      console.log(key, keyPath);
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath);
    },
  },
};
</script>

<style lang="scss" scoped>
/deep/ .el-menu--collapse {
  width: 185px !important;
}
</style>

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

前端老实人

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值