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>

父组件中使用实例:

相关推荐
小小199213 小时前
vue 单页面请求
开发语言·前端·javascript
hhb_61813 小时前
JavaScript 本地存储与动态数据渲染实战案例
开发语言·javascript·ecmascript
无心使然13 小时前
Openlayers调用ArcGis要素服务之一 ——要素查询 (/query)
前端·javascript·数据可视化
kyriewen1113 小时前
Next.js部署:从本地跑得欢,到线上飞得稳
开发语言·前端·javascript·科技·react.js·前端框架·ecmascript
天天向上102414 小时前
openlayers 加载Shapefile文件
前端·javascript·html
wuxianda103014 小时前
苹果App上架4.3a问题3天解决方案汇报总结
开发语言·javascript·uni-app·ecmascript·ios上架·苹果上架
琹箐14 小时前
今天吃什么干什么随机生成
javascript·css·css3
卷Java14 小时前
ReAct范式实战:让Agent学会边想边做
javascript·react.js·大模型·llm·ecmascript·multi-agent
吴声子夜歌14 小时前
Vue3——UI组件库Element Plus(二)
javascript·vue.js·ui·elementplus
zhensherlock14 小时前
Protocol Launcher 系列:Beorg 高效任务管理的协议支持
前端·javascript·typescript·node.js·自动化·github·js