el-menu自定义的导航

**

Layout(整体的框架)

**

<template>
  <div>
    <el-radio-group v-model="isCollapse" style="margin-left: 320px;">
      <el-radio-button :label="false">展开</el-radio-button>
      <el-radio-button :label="true">收起</el-radio-button>
    </el-radio-group>
    <Sidebar :menu-list="menuList" :collapse="isCollapse" />
  </div>
</template>
<script>
import Sidebar from '@/layout/components/SideBar.vue'
export default {
  name: 'Layout',
  components: {
    Sidebar
  },
  data() {
    return {
      isCollapse: false,
      'menuList': [
        {
          'path': '1', // 菜单项所对应的路由路径
          'title': '功能1', // 菜单项名称
          'children': [] // 是否有子菜单,若没有,则为[]
        },
        {
          'path': '2',
          'title': '功能5555552'
        //   'children': []
        },
        {
          'path': '3',
          'title': '功能3',
          'children': [
            {
              'path': '3-1',
              'title': '功能3-1'
            //   'children': []
            },
            {
              'path': '3-2',
              'title': '功能3-2',
              'children': [
                {
                  'path': '3-2-1',
                  'title': '功能3-2-1'
                //   'children': []
                }
              ]
            },
            {
              'path': '3-3',
              'title': '功能3-3'
            //   'children': []
            }
          ]
        },
        {
          'path': '4',
          'title': '功能4',
          'children': [
            {
              'path': '4-1',
              'title': '功能4-1'
            }
          ]
        }

      ]

    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    }
  }

}
</script>
<style  scroped>

</style>


SideBar


<template>
  <el-menu default-active="3-2-1" class="el-menu-vertical-demo" :collapse="collapse" @open="handleOpen" @close="handleClose">
    <sidebar-item v-for="menu in menuList" :key="menu.path" :item="menu" :collapse="collapse" />
  </el-menu>
</template>
<script>

import SidebarItem from './SidebarItem'

export default {
  name: 'Sidebar',
  components: { SidebarItem },
  props: {
    menuList: {
      type: Array,
      required: true
    },
    collapse: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    handleOpen(key, keyPath) {
      console.log(key, keyPath)
    },
    handleClose(key, keyPath) {
      console.log(key, keyPath)
    }
  }
}
</script>
<style scoped>
.el-menu-vertical-demo:not(.el-menu--collapse) {
  width: 200px;
  min-height: 400px;
}
</style>

SidebarItem

<template>
  <div>
    <div v-if="item.children">
      <template v-if="item.children.length == 0">
        <el-menu-item :index="item.path">
          <i class="el-icon-document" />
          <span slot="title">{{ item.title }}</span>
        </el-menu-item>
      </template>
      <el-submenu v-else :index="item.path">
        <template slot="title">
          <i class="el-icon-location" />
          <span v-show="!collapse" slot="title">{{ item.title }}</span>
        </template>
        <template v-for="child in item.children">
          <sidebar-item
            v-if="child.children&&child.children.length>0"
            :key="child.path"
            :item="child"
          />
          <el-menu-item v-else :key="child.path" :index="child.path">
            <i class="el-icon-location" />
            {{ child.title }}
          </el-menu-item>
        </template>
      </el-submenu>
    </div>
    <div v-else>
      <template>
        <el-menu-item :index="item.path">
          <i class="el-icon-document" />
          <span slot="title">{{ item.title }}</span>
        </el-menu-item>
      </template>
    </div>
  </div>
</template>

<script>

export default {
  name: 'SidebarItem',
  props: {
    item: {
      type: Object,
      required: true
    },
    collapse: {
      type: Boolean,
      default: false
    }
  }
}
</script>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值