vue循环三级导航

vue怎么实现循环三级导航呢?用的是element框架。已经循环出了二级,但是原理理解不够透彻,不知道三级甚至四级导航如何循环出来。请高人指点

<template>
    <div class="sidebar">

        <el-menu :default-active="onRoutes" class="el-menu-vertical-demo" theme="dark" unique-opened router>
            <template v-for="item in items">

                <template v-if="item.subs">
                    <el-submenu :index="item.index">
                        <template slot="title">{{ item.title }}</template>
                        <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                            {{ subItem.title }}
                        </el-menu-item>
                    </el-submenu>
                </template>

                <template v-else>
                    <el-menu-item :index="item.index">
                        {{ item.title }}
                    </el-menu-item>
                </template>

            </template>
        </el-menu>

    </div>
</template>

<script>
    export default {
        data() {
            return {
                items: [
                    {
                        index: 'readme',
                        title: '首页'
                    },
                    {
                        index: '2',
                        title: '表格',
                        subs: [
                            {
                                index: 'basetable',
                                title: '基础表格',
                                chl:[
                                    {
                                        index: 'basetable',
                                        title: '测试1'
                                    },
                                    {
                                        index: 'basetable',
                                        title: '测试2',
                                        chl:[
                                            {
                                                index: 'basetable',
                                                title: '测试3'
                                            },
                                            {
                                                index: 'basetable',
                                                title: '测试4'
                                            }
                                        ]
                                    }
                                ]
                            },
                            {
                                index: 'vuetable',
                                title: 'Vue表格组件'
                            }
                        ]
                    },
                    {
                        index: '3',
                        title: '表单',
                        subs: [
                            {
                                index: 'baseform',
                                title: '基本表单'
                            },
                            {
                                index: 'vueeditor',
                                title: '编辑器'
                            },
                            {
                                index: 'markdown',
                                title: 'markdown'
                            },
                            {
                                index: 'upload',
                                title: '文件上传'
                            }
                        ]
                    },
                    {
                        index: 'basecharts',
                        title: '图表'
                    },
                    {
                        index: 'drag',
                        title: '拖拽'
                    }
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
        }
    }
</script>

图片描述

回答:

继续往里套啊,标题用template slot ,下面紧跟 el-menu-item

看这个侧栏第二个不带icon的示例
http://element.eleme.io/#/zh-…

回答:

   <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
        text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
        <template v-for="item in items">
            <!--循环-->
            <template v-if="item.subs">
                <el-submenu :index="item.index" :key="item.index">
                    <template slot="title">
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                    </template>
                    <el-menu-item v-for="(subItem,i) in item.subs" :key="i" :index="subItem.index">
                        {{ subItem.title }}
                    </el-menu-item>
                    <!--3级菜单-->
                    <template v-for="subs in item.subs">
                        <template v-if="subs.subs">
                            <el-submenu :index="subs.index" :key="subs.index">
                                <template slot="title">
                                    <i :class="subs.icon"></i><span slot="title">{{ subs.title }}</span>
                                </template>
                                <el-menu-item v-for="(subItem,i) in subs.subs" :key="i" :index="subItem.index">
                                    {{ subItem.title }}
                                </el-menu-item>
                            </el-submenu>
                        </template>
                    </template>
                </el-submenu>
            </template>
            <template v-else>
                <el-menu-item :index="item.index" :key="item.index">
                    <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
                </el-menu-item>
            </template>
        </template>
    </el-menu>

暂无评论

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注