Blame view
src/common/Sidebar.vue
6.01 KB
1172ebb79 auto commit the c... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 |
<template> <div class="sidebar"> <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> <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> </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> </div> </template> <script> import bus from './bus'; export default { data() { return { collapse: false, items: [ { icon: 'el-icon-lx-home', index: 'dashboard', title: '系统首页' }, { icon: 'el-icon-lx-cascades', index: 'table', title: '基础表格' }, { icon: 'el-icon-lx-copy', index: 'tabs', title: 'tab选项卡' }, { icon: 'el-icon-lx-calendar', index: '3', title: '表单相关', subs: [ { index: 'form', title: '基本表单' }, { index: '3-2', title: '三级菜单', subs: [ { index: 'editor', title: '富文本编辑器' }, { index: 'markdown', title: 'markdown编辑器' } ] }, { index: 'upload', title: '文件上传' } ] }, { icon: 'el-icon-lx-emoji', index: 'icon', title: '自定义图标' }, { icon: 'el-icon-pie-chart', index: 'charts', title: 'schart图表' }, { icon: 'el-icon-rank', index: '6', title: '拖拽组件', subs: [ { index: 'drag', title: '拖拽列表' }, { index: 'dialog', title: '拖拽弹框' } ] }, { icon: 'el-icon-lx-global', index: 'i18n', title: '国际化功能' }, { icon: 'el-icon-lx-warn', index: '7', title: '错误处理', subs: [ { index: 'permission', title: '权限测试' }, { index: '404', title: '404页面' } ] }, { icon: 'el-icon-lx-redpacket_fill', index: '/donate', title: '支持作者' } ] }; }, computed: { onRoutes() { return this.$route.path.replace('/', ''); } }, created() { // 通过 Event Bus 进行组件间通信,来折叠侧边栏 bus.$on('collapse', msg => { this.collapse = msg; bus.$emit('collapse-content', msg); }); } }; </script> <style scoped> .sidebar { display: block; position: absolute; left: 0; top: 70px; bottom: 0; overflow-y: scroll; } .sidebar::-webkit-scrollbar { width: 0; } .sidebar-el-menu:not(.el-menu--collapse) { width: 250px; } .sidebar > ul { height: 100%; } </style> |