Sidebar.vue 5.3 KB
Newer Older
L
lin-xin 已提交
1 2
<template>
    <div class="sidebar">
L
lin-xin 已提交
3
        <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#324157"
L
lin-xin 已提交
4
            text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
L
lin-xin 已提交
5 6
            <template v-for="item in items">
                <template v-if="item.subs">
L
lin-xin 已提交
7 8
                    <el-submenu :index="item.index" :key="item.index">
                        <template slot="title">
L
lin-xin 已提交
9
                            <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
L
lin-xin 已提交
10
                        </template>
L
lin-xin 已提交
11 12 13 14 15 16 17 18 19 20 21
                        <template v-for="subItem in item.subs">
                            <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                                <template slot="title">{{ subItem.title }}</template>
                                <el-menu-item v-for="(threeItem,i) in subItem.subs" :key="i" :index="threeItem.index">
                                    {{ threeItem.title }}
                                </el-menu-item>
                            </el-submenu>
                            <el-menu-item v-else :index="subItem.index" :key="subItem.index">
                                {{ subItem.title }}
                            </el-menu-item>
                        </template>
L
lin-xin 已提交
22 23 24
                    </el-submenu>
                </template>
                <template v-else>
L
lin-xin 已提交
25
                    <el-menu-item :index="item.index" :key="item.index">
L
lin-xin 已提交
26
                        <i :class="item.icon"></i><span slot="title">{{ item.title }}</span>
L
lin-xin 已提交
27 28 29 30 31 32 33 34
                    </el-menu-item>
                </template>
            </template>
        </el-menu>
    </div>
</template>

<script>
L
lin-xin 已提交
35
    import bus from '../common/bus';
L
lin-xin 已提交
36 37 38
    export default {
        data() {
            return {
L
lin-xin 已提交
39
                collapse: false,
L
lin-xin 已提交
40 41 42
                items: [
                    {
                        icon: 'el-icon-setting',
L
lin-xin 已提交
43 44
                        index: 'dashboard',
                        title: '系统首页'
L
lin-xin 已提交
45 46
                    },
                    {
L
lin-xin 已提交
47
                        icon: 'el-icon-tickets',
L
lin-xin 已提交
48 49
                        index: 'table',
                        title: '基础表格'
L
lin-xin 已提交
50
                    },
L
lin-xin 已提交
51 52 53 54 55
                    {
                        icon: 'el-icon-message',
                        index: 'tabs',
                        title: 'tab选项卡'
                    },
L
lin-xin 已提交
56 57 58
                    {
                        icon: 'el-icon-date',
                        index: '3',
L
lin-xin 已提交
59
                        title: '表单相关',
L
lin-xin 已提交
60 61
                        subs: [
                            {
L
lin-xin 已提交
62
                                index: 'form',
L
lin-xin 已提交
63 64 65
                                title: '基本表单'
                            },
                            {
L
lin-xin 已提交
66
                                index: '3-2',
L
lin-xin 已提交
67
                                title: '三级菜单',
L
lin-xin 已提交
68 69 70 71 72 73 74 75 76 77
                                subs: [
                                    {
                                        index: 'editor',
                                        title: '富文本编辑器'
                                    },
                                    {
                                        index: 'markdown',
                                        title: 'markdown编辑器'
                                    },
                                ]
L
lin-xin 已提交
78 79 80 81 82 83 84 85 86
                            },
                            {
                                index: 'upload',
                                title: '文件上传'
                            }
                        ]
                    },
                    {
                        icon: 'el-icon-star-on',
L
lin-xin 已提交
87
                        index: 'charts',
L
lin-xin 已提交
88
                        title: 'schart图表'
L
lin-xin 已提交
89
                    },
L
lin-xin 已提交
90 91 92 93 94
                    {
                        icon: 'el-icon-rank',
                        index: 'drag',
                        title: '拖拽列表'
                    },
L
lin-xin 已提交
95 96
                    {
                        icon: 'el-icon-error',
L
lin-xin 已提交
97 98 99 100 101 102 103 104 105 106 107 108
                        index: '6',
                        title: '错误处理',
                        subs: [
                            {
                                index: 'permission',
                                title: '权限测试'
                            },
                            {
                                index: '404',
                                title: '404页面'
                            }
                        ]
L
lin-xin 已提交
109 110 111 112 113 114 115 116
                    }
                ]
            }
        },
        computed:{
            onRoutes(){
                return this.$route.path.replace('/','');
            }
L
lin-xin 已提交
117 118
        },
        created(){
L
lin-xin 已提交
119
            // 通过 Event Bus 进行组件间通信,来折叠侧边栏
L
lin-xin 已提交
120 121 122
            bus.$on('collapse', msg => {
                this.collapse = msg;
            })
L
lin-xin 已提交
123 124 125 126 127 128 129 130 131 132 133
        }
    }
</script>

<style scoped>
    .sidebar{
        display: block;
        position: absolute;
        left: 0;
        top: 70px;
        bottom:0;
L
lin-xin 已提交
134 135 136 137
        overflow-y: scroll;
    }
    .sidebar::-webkit-scrollbar{
        width: 0;
L
lin-xin 已提交
138 139 140
    }
    .sidebar-el-menu:not(.el-menu--collapse){
        width: 250px;
L
lin-xin 已提交
141 142 143 144 145
    }
    .sidebar > ul {
        height:100%;
    }
</style>