Commit 540595646d784e43a4a5da85d3e7e3ab02c4fa4f
1 parent
d6ef0ccd
v3.8.2 topNav自定义隐藏侧边栏路由
Showing
1 changed file
with
10 additions
and
16 deletions
yudao-ui-admin/src/components/TopNav/index.vue
| 1 | 1 | <template> |
| 2 | 2 | <el-menu |
| 3 | - :default-active="activeMenu" | |
| 4 | - mode="horizontal" | |
| 5 | - @select="handleSelect" | |
| 3 | + :default-active="activeMenu" | |
| 4 | + mode="horizontal" | |
| 5 | + @select="handleSelect" | |
| 6 | 6 | > |
| 7 | 7 | <template v-for="(item, index) in topMenus"> |
| 8 | 8 | <el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber" |
| ... | ... | @@ -16,9 +16,9 @@ |
| 16 | 16 | <template slot="title">更多菜单</template> |
| 17 | 17 | <template v-for="(item, index) in topMenus"> |
| 18 | 18 | <el-menu-item |
| 19 | - :index="item.path" | |
| 20 | - :key="index" | |
| 21 | - v-if="index >= visibleNumber" | |
| 19 | + :index="item.path" | |
| 20 | + :key="index" | |
| 21 | + v-if="index >= visibleNumber" | |
| 22 | 22 | ><svg-icon :icon-class="item.meta.icon" /> |
| 23 | 23 | {{ item.meta.title }}</el-menu-item |
| 24 | 24 | > |
| ... | ... | @@ -30,13 +30,14 @@ |
| 30 | 30 | <script> |
| 31 | 31 | import { constantRoutes } from "@/router"; |
| 32 | 32 | |
| 33 | +// 隐藏侧边栏路由 | |
| 34 | +const hideList = ['/index', '/user/profile']; | |
| 35 | + | |
| 33 | 36 | export default { |
| 34 | 37 | data() { |
| 35 | 38 | return { |
| 36 | 39 | // 顶部栏初始数 |
| 37 | 40 | visibleNumber: 5, |
| 38 | - // 是否为首次加载 | |
| 39 | - isFrist: false, | |
| 40 | 41 | // 当前激活菜单的 index |
| 41 | 42 | currentIndex: undefined |
| 42 | 43 | }; |
| ... | ... | @@ -88,17 +89,10 @@ export default { |
| 88 | 89 | activeMenu() { |
| 89 | 90 | const path = this.$route.path; |
| 90 | 91 | let activePath = path; |
| 91 | - if (path.lastIndexOf("/") > 0) { | |
| 92 | + if (path !== undefined && path.lastIndexOf("/") > 0 && hideList.indexOf(path) === -1) { | |
| 92 | 93 | const tmpPath = path.substring(1, path.length); |
| 93 | 94 | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); |
| 94 | 95 | this.$store.dispatch('app/toggleSideBarHide', false); |
| 95 | - } else if ("/index" == path || "" == path) { | |
| 96 | - if (!this.isFrist) { | |
| 97 | - this.isFrist = true; | |
| 98 | - } else { | |
| 99 | - activePath = "index"; | |
| 100 | - } | |
| 101 | - this.$store.dispatch('app/toggleSideBarHide', true); | |
| 102 | 96 | } else if(!this.$route.children) { |
| 103 | 97 | activePath = path; |
| 104 | 98 | this.$store.dispatch('app/toggleSideBarHide', true); | ... | ... |