Skip to content

Commit dda34a2

Browse files
committed
v3.8.2 topNav自定义隐藏侧边栏路由
1 parent ab47aae commit dda34a2

File tree

1 file changed

+10
-16
lines changed

1 file changed

+10
-16
lines changed

src/components/TopNav/index.vue

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<template>
22
<el-menu
3-
:default-active="activeMenu"
4-
mode="horizontal"
5-
@select="handleSelect"
3+
:default-active="activeMenu"
4+
mode="horizontal"
5+
@select="handleSelect"
66
>
77
<template v-for="(item, index) in topMenus">
88
<el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber"
@@ -16,9 +16,9 @@
1616
<template slot="title">更多菜单</template>
1717
<template v-for="(item, index) in topMenus">
1818
<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"
2222
><svg-icon :icon-class="item.meta.icon" />
2323
{{ item.meta.title }}</el-menu-item
2424
>
@@ -30,13 +30,14 @@
3030
<script>
3131
import { constantRoutes } from "@/router";
3232
33+
// 隐藏侧边栏路由
34+
const hideList = ['/index', '/user/profile'];
35+
3336
export default {
3437
data() {
3538
return {
3639
// 顶部栏初始数
3740
visibleNumber: 5,
38-
// 是否为首次加载
39-
isFrist: false,
4041
// 当前激活菜单的 index
4142
currentIndex: undefined
4243
};
@@ -88,17 +89,10 @@ export default {
8889
activeMenu() {
8990
const path = this.$route.path;
9091
let activePath = path;
91-
if (path.lastIndexOf("/") > 0) {
92+
if (path !== undefined && path.lastIndexOf("/") > 0 && hideList.indexOf(path) === -1) {
9293
const tmpPath = path.substring(1, path.length);
9394
activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/"));
9495
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);
10296
} else if(!this.$route.children) {
10397
activePath = path;
10498
this.$store.dispatch('app/toggleSideBarHide', true);

0 commit comments

Comments
 (0)