Vue3使用ElementPlus实现菜单的无限递归

菜单组件childrenmenu.vue

javascript 复制代码
<template>
    <template v-if=" item.children && item.children?.length > 0" >
        <el-sub-menu   :index="item.meunid">
            <template #title>
                <component v-if="item.meunicon != undefined && item.meunicon != null" class="icons" :is="item.meunicon" />
                <span style="width: 100%; text-align: center;">{{ item.meunname }}</span>
            </template>
            <childrenmenu v-for="childItem in item.children" :key="childItem.meunid" :item="childItem" />
        </el-sub-menu>
    </template>
    <template v-else>
        <el-menu-item :index="item.meunpath" :key="item.meunid">
            <component v-if="item.meunicon != undefined && item.meunicon != null" class="icons" :is="item.meunicon" />
            <span style="width: 100%; text-align: center;">{{ item.meunname }}</span>
        </el-menu-item>
    </template>
</template>
<script setup lang="ts">

const props=defineProps(['item'])
</script>
<style lang="scss" scoped>
svg {
    // width: 50%;
    height: 100%;
}
</style>

父组件中使用实例:

相关推荐
@yanyu6661 天前
07-引入element布局及spring boot完善后端
javascript·vue.js·spring boot
@大迁世界1 天前
2026年React大洗牌:React Hooks 将迎来重大升级
前端·javascript·react.js·前端框架·ecmascript
风止何安啊1 天前
为什么要有 TypeScript?让 JS 告别 “薛定谔的 Bug”
前端·javascript·面试
海天鹰1 天前
SOC架构
javascript
前进的李工1 天前
MySQL角色管理:权限控制全攻略
前端·javascript·数据库·mysql
NPE~1 天前
[App逆向]环境搭建下篇 — — 逆向源码+hook实战
android·javascript·python·教程·逆向·hook·逆向分析
洒满阳光的庄园1 天前
Electron 桌面端打包流程说明
前端·javascript·electron
子琦啊1 天前
【算法复习】数组与双指针篇
javascript·算法
SuperEugene1 天前
前端通用基础组件设计:按钮/输入框/弹窗,统一设计标准|组件化设计基础篇
前端·javascript·vue.js·架构
范什么特西1 天前
web练习
java·前端·javascript