001_左侧公共导航菜单(h3)
- \src\components\CommonAside.vue
<template>
<el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
<!-- 有子级菜单-->
<el-submenu index="1">
<template slot="title">
<i class="el-icon-location"></i>
<span>导航一</span>
</template>
<el-menu-item-group>
<el-menu-item index="1-1">选项1</el-menu-item>
<el-menu-item index="1-2">选项2</el-menu-item>
</el-menu-item-group>
</el-submenu>
<!-- 无子级菜单-->
<el-menu-item index="2">
<i class="el-icon-menu"></i>
<span slot="title">导航二</span>
</el-menu-item>
</el-menu>
</template>
<script>
export default {}
</script>
<style lang="scss" scoped>
.el-menu {
height: 100%;
border: none;
}
</style>

- \src\components\CommonAside.vue
<template>
<el-menu default-active="2" class="el-menu-vertical-demo" background-color="#545c64" text-color="#fff" active-text-color="#ffd04b">
<!-- 无子级菜单-->
<el-menu-item :index="item.path" v-for="item in noChildren" :key="item.path">
<i :class="'el-icon-' + item.icon"></i>
<span slot="title">{{ item.label }}</span>
</el-menu-item>
<!-- 有子级菜单-->
<el-submenu index="2" v-for="(item, index) in hasChildren" :key="index">
<template slot="title">
<i :class="'el-icon-' + item.icon"></i>
<span>{{ item.label }}</span>
</template>
<el-menu-item-group>
<el-menu-item index="subItem.path" v-for="(subItem, subIndex) in item.children" :key="subIndex">
<i :class="'el-icon-' + subItem.icon"></i>
<span>{{ subItem.label }}</span>
</el-menu-item>
</el-menu-item-group>
</el-submenu>
</el-menu>
</template>
<script>
export default {
computed: {
noChildren() {
return this.asideMenu.filter(item => !item.children)
},
hasChildren() {
return this.asideMenu.filter(item => item.children)
}
},
data() {
return {
asideMenu: [
{
path: '/',
name: 'Home',
label: '首页',
icon: 's-home'
},
{
label: '其他',
icon: 'user',
children: [
{
path: '/page1',
name: 'page1',
label: '页面1',
icon: 'setting'
}
]
}
]
}
},
methods: {
clickMenu(item) {
this.$router.push({ name: item.name })
this.$store.commit('selectMenu', item)
}
}
}
</script>
<style lang="scss" scoped>
.el-menu {
height: 100%;
border: none;
}
</style>
