Browse Source

feat[menu]: add alwaysShow option

Pan 7 years ago
parent
commit
2c7586ccb8
2 changed files with 4 additions and 1 deletions
  1. 3 0
      src/router/index.js
  2. 1 1
      src/views/layout/components/Sidebar/SidebarItem.vue

+ 3 - 0
src/router/index.js

@@ -11,6 +11,9 @@ import Layout from '../views/layout/Layout'
11 11
 
12 12
 /**
13 13
 * hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
14
+* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
15
+*                                if not set alwaysShow, only more than one route under the children
16
+*                                it will becomes nested mode, otherwise not show the root menu
14 17
 * redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
15 18
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
16 19
 * meta : {

+ 1 - 1
src/views/layout/components/Sidebar/SidebarItem.vue

@@ -2,7 +2,7 @@
2 2
   <div class="menu-wrapper">
3 3
     <template v-for="item in routes" v-if="!item.hidden&&item.children">
4 4
 
5
-      <router-link v-if="item.children.length===1 && !item.children[0].children" :to="item.path+'/'+item.children[0].path" :key="item.children[0].name">
5
+      <router-link v-if="item.children.length===1 && !item.children[0].children && !item.alwaysShow" :to="item.path+'/'+item.children[0].path" :key="item.children[0].name">
6 6
         <el-menu-item :index="item.path+'/'+item.children[0].path" :class="{'submenu-title-noDropdown':!isNest}">
7 7
           <svg-icon v-if="item.children[0].meta&&item.children[0].meta.icon" :icon-class="item.children[0].meta.icon"></svg-icon>
8 8
           <span v-if="item.children[0].meta&&item.children[0].meta.title">{{item.children[0].meta.title}}</span>