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 | <template> | 1 | <template> |
| 2 | <el-menu | 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 | <template v-for="(item, index) in topMenus"> | 7 | <template v-for="(item, index) in topMenus"> |
| 8 | <el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber" | 8 | <el-menu-item :style="{'--theme': theme}" :index="item.path" :key="index" v-if="index < visibleNumber" |
| @@ -16,9 +16,9 @@ | @@ -16,9 +16,9 @@ | ||
| 16 | <template slot="title">更多菜单</template> | 16 | <template slot="title">更多菜单</template> |
| 17 | <template v-for="(item, index) in topMenus"> | 17 | <template v-for="(item, index) in topMenus"> |
| 18 | <el-menu-item | 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 | ><svg-icon :icon-class="item.meta.icon" /> | 22 | ><svg-icon :icon-class="item.meta.icon" /> |
| 23 | {{ item.meta.title }}</el-menu-item | 23 | {{ item.meta.title }}</el-menu-item |
| 24 | > | 24 | > |
| @@ -30,13 +30,14 @@ | @@ -30,13 +30,14 @@ | ||
| 30 | <script> | 30 | <script> |
| 31 | import { constantRoutes } from "@/router"; | 31 | import { constantRoutes } from "@/router"; |
| 32 | 32 | ||
| 33 | +// 隐藏侧边栏路由 | ||
| 34 | +const hideList = ['/index', '/user/profile']; | ||
| 35 | + | ||
| 33 | export default { | 36 | export default { |
| 34 | data() { | 37 | data() { |
| 35 | return { | 38 | return { |
| 36 | // 顶部栏初始数 | 39 | // 顶部栏初始数 |
| 37 | visibleNumber: 5, | 40 | visibleNumber: 5, |
| 38 | - // 是否为首次加载 | ||
| 39 | - isFrist: false, | ||
| 40 | // 当前激活菜单的 index | 41 | // 当前激活菜单的 index |
| 41 | currentIndex: undefined | 42 | currentIndex: undefined |
| 42 | }; | 43 | }; |
| @@ -88,17 +89,10 @@ export default { | @@ -88,17 +89,10 @@ export default { | ||
| 88 | activeMenu() { | 89 | activeMenu() { |
| 89 | const path = this.$route.path; | 90 | const path = this.$route.path; |
| 90 | let activePath = path; | 91 | let activePath = path; |
| 91 | - if (path.lastIndexOf("/") > 0) { | 92 | + if (path !== undefined && path.lastIndexOf("/") > 0 && hideList.indexOf(path) === -1) { |
| 92 | const tmpPath = path.substring(1, path.length); | 93 | const tmpPath = path.substring(1, path.length); |
| 93 | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); | 94 | activePath = "/" + tmpPath.substring(0, tmpPath.indexOf("/")); |
| 94 | this.$store.dispatch('app/toggleSideBarHide', false); | 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 | } else if(!this.$route.children) { | 96 | } else if(!this.$route.children) { |
| 103 | activePath = path; | 97 | activePath = path; |
| 104 | this.$store.dispatch('app/toggleSideBarHide', true); | 98 | this.$store.dispatch('app/toggleSideBarHide', true); |