main.js引入全局组件
1. 组件
menu/index.vue
<template>
<el-menu :unique-opened="true" :default-active="this.$store.state.menuData.menuActive" class="el-menu-vertical-demo" :background-color="backgroundColor" :text-color="textColor" :active-text-color="activeTextColor">
<subMenu :menuList="sideNavMenu"></subMenu>
</el-menu>
</template>
<script>
export default {
name: "index",
props: {},
data() {
return {
backgroundColor: "#EAEEF6",
textColor: "#3F434E",
activeTextColor: "#2A60CC",
sideNavMenu: [
{
"id": 1,
"name": "首页",
"code": "01",
"parentId": "",
"path": "/home",
"icon": "icon-home",
"level": 1,
"resourceType": 0,
"systemType": "",
"status": "",
"sortOrder": 1,
"children": ""
},
{
"id": 2,
"name": "关于",
"code": "02",
"parentId": "",
"path": "/about",
"icon": "icon-about",
"level": 1,
"resourceType": 0,
"systemType": "",
"status": "",
"sortOrder": 2,
"children": [
{
"id": 3,
"name": "关于我们",
"code": "0201",
"parentId": "2",
"path": "/aboutUs",
"icon": "",
"level": 2,
"resourceType": 0,
"systemType": "",
"status": "",
"sortOrder": 1,
"children": ""
}
]
},
]
}
},
mounted() { },
methods: {},
watch: {},
created() { },
}
</script>
<style scoped>
.el-menu {
text-align: left;
}
.el-menu-vertical-demo {
width: 100%;
height: 100%;
box-sizing: border-box;
}
</style>
menu/submenu.vue
<template>
<div>
<div v-for="(list,index) in this.menuList" :key="index">
<div v-if="list.resourceType === 0" class="menu-nav">
<el-submenu v-if="!!list.children" :key="list.id" :index="String(list.id)">
<template slot="title">
<i class="menu_icon" :class="list.icon"></i>
<span slot="title">{{ list.name}}</span>
</template>
<subMenu :menuList="list.children"></subMenu>
</el-submenu>
<el-menu-item v-else :index="list.path">
<router-link :target="targeLink(list.path)?'_blank':''" :to="list.path">
<i class="menu_icon" :class="list.icon"></i>
<span>{{list.name}}</span>
</router-link>
</el-menu-item>
</div>
<div v-else-if="list.resourceType === 1">
<el-menu-item v-if="!!list.children" :index="list.path" :key="list.id">
<router-link :target="targeLink(list.path)?'_blank':''" :to="list.path">
<i class="menu_icon" :class="list.icon"></i>
<span>{{list.name}}</span>
</router-link>
</el-menu-item>
</div>
</div>
</div>
</template>
<script>
export default {
name: "submenu",
data() {
return {}
},
props: {
menuList: Array
},
mounted() { },
methods: {
targeLink(path) {
if (path === '/aboutUs') {
return true
} else {
return false
}
}
},
watch: {},
created() { },
}
</script>
<style lang="scss" scoped>
@import "style.scss";
</style>
menu/style.scss
@charset "utf-8";
/deep/ .el-menu-item,
/deep/ .el-submenu__title {
font-size: 18px;
}
/deep/ .el-submenu__title:hover,
.el-submenu__title:hover [class*="el-icon-"],
.el-submenu__title:hover [class*=" icon-"],
.el-submenu__title:hover [class^=icon-],
.el-submenu__title:hover .menu_icon {
color: $menu_active_text_color !important;
}
/deep/ .el-submenu {
&.is-opened.is-active {
// .el-submenu__title [class*="el-icon-"],
// .el-submenu__title [class*=" icon-"],
// .el-submenu__title [class*="icon-"],
&>.el-submenu__title .menu_icon,
&>.el-submenu__title {
color: $menu_active_text_color !important;
}
&>.el-submenu__title {
font-weight: bold;
background-color: $menu_active_bg_color !important;
}
}
}
.el-menu-item:hover,
.el-menu-item:hover [class*=" icon-"],
.el-menu-item:hover [class^=icon-],
.el-menu-item.is-active {
color: $menu_active_text_color !important;
background-color: $menu_active_bg_color !important;
}
// router-link / a 标签
a {
display: block;
color: #3F434E;
}
.el-menu-item:hover a,
.el-menu-item.is-active a {
color: $menu_active_text_color ;
}
/deep/ .el-submenu__icon-arrow {
font-size: 18px;
}
/deep/ .el-icon-arrow-down:before {
content: "\E790";
}
[class*="el-icon-"],
[class*=" icon-"],
[class^=icon-] {
font-size: 20px;
margin-right: 5px;
// color: #f00;
}
2. 调用
<Menu></Menu>