zoukankan      html  css  js  c++  java
  • 超级好用的elementui动态循环菜单

    <template>
        <div>
            <el-menu
                @select="selectMenu"
                :default-active="currentIndexLight"
                class="el-menu-vertical-demo"
                @open="handleOpen"
                @close="handleClose"
                background-color="#545c64"
                text-color="#fff"
                :router="startRouter"
                active-text-color="#ffd04b"
            >
                <!--  
                :default-openeds="arrIndex"
                -->
                <div v-for="item in menuList" :key="item.path">
                    <!-- 没有子菜单 -->
                    <template v-if="item.children && item.children.length == 0">
                        <el-menu-item :index="item.path">
                            <i class="el-icon-menu"></i>
                            {{item.title}}
                        </el-menu-item>
                    </template>
    
                    <!-- 有子菜单 -->
                    <el-submenu v-else :index="item.path">
                        <template slot="title">
                            <i class="el-icon-menu"></i>
                            {{item.title}}
                        </template>
    
                        <template v-for="child in item.children">
                            <!-- 这里是类似递归循环 -->
                            <sidebar-item
                                v-if="child.children&&child.children.length>0"
                                :item="child"
                                :key="child.path"
                            />
                            <el-menu-item v-else :key="child.path" :index="child.path">
                                <i class="el-icon-location"></i>
                                {{child.title}}
                            </el-menu-item>
                        </template>
                    </el-submenu>
                </div>
            </el-menu>
        </div>
    </template>
    <script>
    
    
    export default {
        data() {
            return {
    
                startRouter: true,//开启路由标识, ,启用该模式会在激活导航时以 index 作为 path 进行路由跳转
                currentIndexLight: '',//当前激活菜单的 index  高亮显示
                arrIndex: [],
                menuList: [
                    {
                        "path": "/awaitdoing",     //菜单项所对应的路由路径
                        "title": "功能1",     //菜单项名称
                        "children": []        //是否有子菜单,若没有,则为[]
                    },
                    {
                        "path": "/quickset",
                        "title": "功能2",
                        "children": []
                    },
                    {
                        "path": "aa",
                        "title": "功能3",
                        "children": [
                            {
                                "path": "/awaitdo",
                                "title": "功能3-1",
                                "children": []
                            },
                            {
                                "path": "/alreadygreen",
                                "title": "功能3-2",
                                "children": []
                            },
                            {
                                "path": "/approvedby",
                                "title": "功能3-3",
                                "children": []
                            },
                        ]
                    },
                    {
                        "path": "/func10",
                        "title": "功能10",
                        "children": []
                    }
                ]
    
            }
        },
    
        methods: {
            selectMenu(key, keyPath) {
                console.log(key, keyPath)
                this.currentIndexLight = key;
            },
            // 展开指定的 sub-menu
            handleOpen(key, keyPath) {
                console.log('展开的时候触发', key, keyPath);
    
            },
    
            //    收起指定的 sub-menu
            handleClose(key, keyPath) {
                console.log('收起的时候触发', key, keyPath);
            }
    
    
        }
    }
    </script>
    

    作者:明月人倚楼
    出处:https://www.cnblogs.com/IwishIcould/

    想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!

    如果觉得这篇文章对你有小小的帮助的话,记得在右下角点个“推荐”哦,或者关注博主,在此感谢!

    万水千山总是情,打赏5毛买辣条行不行,所以如果你心情还比较高兴,也是可以扫码打赏博主(っ•̀ω•́)っ✎⁾⁾!

    想问问题,打赏了卑微的博主,求求你备注一下的扣扣或者微信;这样我好联系你;(っ•̀ω•́)っ✎⁾⁾!

    支付宝
    微信
    本文版权归作者所有,欢迎转载,未经作者同意须保留此段声明,在文章页面明显位置给出原文连接
    如果文中有什么错误,欢迎指出。以免更多的人被误导。
  • 相关阅读:
    恢复计算机崩溃数据的五款最佳Linux发行版
    不敢想象!Vim使用者的“大脑”竟是这样
    开发者和系统管理者最喜爱的开源工具Vim 起步学习的五个技巧
    .NET程序与CA对接一直提示重定向
    覆盖原有div或者Input的鼠标移上去描述
    IOS9以上如何导入铃声并设置
    c# 动态调用webserver
    没有终结点在侦听可以接受消息的*这通常是由于不正确的地址或者 SOAP操作导致的
    url 参数的加号变成空格处理
    在git 服务器挂载、创建新的项目、克隆新的项目
  • 原文地址:https://www.cnblogs.com/IwishIcould/p/13693820.html
Copyright © 2011-2022 走看看