微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

基于elementUI的菜单element-menu展示无线级

可以通过 npm install element-menu进行安装

<script>
export default {
    name: 'menu-items',
    props: ['menuList', 'active_menu'],
    render: function(h) {
        var showMenu = menuList => {
            if (menuList.length > 0) {
                return menuList.map((menuItem, index) => {
                    if (menuItem.children.length > 0) {
                        return (
                            <el-submenu index={menuItem.id} key={ menuItem.id} title={menuItem.text}>
                                <template slot="title">
                                    <i class={`iconfont ${menuItem.icon}`}></i>
                                    <span>{menuItem.text}</span>
                                </template>
                                {showMenu(menuItem.children)}
                            </el-submenu>
                        )
                    } else {
                        return(
                            <el-menu-item index={menuItem.path} key={ menuItem.id}>
                                <i class={`iconfont ${menuItem.icon}`}></i>
                                <span slot="title">{menuItem.text}</span>
                            </el-menu-item>
                        )
                    }
                })
            }
        }
        return (
                <el-menu 
                    mode="vertical"
                    default-active={this.active_menu}
                    background-color="#383958"
                    text-color="#fff"
                    active-text-color="#ffd04b"
                    router>
                        <template style="display: block">
                            {showMenu(this.menuList)}
                        </template>
                </el-menu>
        )
    }
}
</script>

在这里插入图片描述

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐