文章來源地址http://www.zghlxwxcb.cn/news/detail-703078.html
<template>
<aside class="menu">
<el-scrollbar>
<el-menu class="menu-main" router :default-active="route.path" unique-opened background-color="#18214C"
text-color="#fff">
<menuItem v-for="item in menuList" :item="item" :key="item.path" />
</el-menu>
</el-scrollbar>
</aside>
</template>
<script setup>
import menuItem from "./components/menuItem.vue"
import { useRoute } from "vue-router"
const route = useRoute()
const menuList = [
{
path: "/index",
component: () => import("@/views/index.vue"),
name: "index",
meta: {
title: "一級(jí)菜單"
}
},
{
path: "/level",
name: "level",
meta: {
title: "多級(jí)菜單"
},
children: [
{
path: "/level/level-1",
name: "level-1",
meta: {
title: "多級(jí)菜單-1"
},
children: [
{
path: "/level/level-1/level-1-1",
component: () => import("@/views/level/level-1/level-1-1.vue"),
name: "level-1-1",
meta: {
title: "多級(jí)菜單-1"
}
}]
},
{
path: "/level/level-2",
component: () => import("@/views/level/level-2.vue"),
name: "level-2",
meta: {
title: "多級(jí)菜單-2"
}
}
]
}
]
</script>
<style lang='scss' scoped>
.menu {
height: 100vh;
overflow: hidden;
background-color: #18214C;
&-main {
border: none;
}
&-main:not(.el-menu--collapse) {
width: 220px;
}
}
</style>
<template>
<template v-if="item.meta && !item.meta.hidden">
<el-sub-menu :index="item.path" :key="item.path" v-if="item?.children?.length > 0">
<template #title>
<el-icon>
<Aim />
</el-icon>
<span>{{ item.meta.title }}</span>
</template>
<menuItem v-for="child in item.children" :item="child" :key="child.path" />
</el-sub-menu>
<el-menu-item v-else :index="item.path">
<el-icon>
<Aim />
</el-icon>
<template #title>{{ item.meta.title }}</template>
</el-menu-item>
</template>
</template>
<script setup name="menuItem">
import { Aim } from '@element-plus/icons-vue'
const props = defineProps({
item: {
type: Object,
default: () => { },
},
})
</script>
<style lang='scss' scoped>
.el-menu-item.is-active {
color: #fff;
background: #2260FF;
}
</style>
文章來源:http://www.zghlxwxcb.cn/news/detail-703078.html
到了這里,關(guān)于Vue3使用遞歸組件封裝El-Menu多級(jí)菜單的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!