Commit b1bdd036 by tang

feat: 监听路由变换,高亮导航

parent e23b2794
<template> <template>
<el-menu <el-menu
:default-active="activeMenu" :default-active="activeMenu"
class="el-menu-vertical gs-subnav" class="el-menu-vertical gs-subnav"
:collapse="false" :collapse="false"
:default-openeds="openeds" :default-openeds="openeds"
@select="handleSelect" @select="handleSelect"
> >
<template v-for="submenu in subNav"> <template v-for="submenu in subNav">
<el-submenu <el-submenu
v-if="submenu.children && submenu.children.length > 0" v-if="submenu.children && submenu.children.length > 0"
:key="submenu.id" :key="submenu.id"
:index="submenu.name" :index="submenu.name"
> >
<template slot="title"> <template slot="title">
<span>{{ submenu.name }}</span> <span>{{ submenu.name }}</span>
...@@ -23,9 +23,9 @@ ...@@ -23,9 +23,9 @@
</template> </template>
<template v-for="third in item.children"> <template v-for="third in item.children">
<el-menu-item <el-menu-item
:key="third.id" :key="third.id"
:index="third.name" :index="third.name"
:class="{ 'is-active': activeMenu === third.id }" :class="{ 'is-active': activeMenu === third.id }"
> >
{{ third.name }} {{ third.name }}
</el-menu-item> </el-menu-item>
...@@ -34,9 +34,9 @@ ...@@ -34,9 +34,9 @@
</template> </template>
<template v-else> <template v-else>
<el-menu-item <el-menu-item
:key="item.id" :key="item.id"
:index="item.name" :index="item.name"
:class="{ 'is-active': activeMenu === item.id }" :class="{ 'is-active': activeMenu === item.id }"
> >
{{ item.name }} {{ item.name }}
</el-menu-item> </el-menu-item>
...@@ -45,9 +45,9 @@ ...@@ -45,9 +45,9 @@
</el-submenu> </el-submenu>
<template v-else> <template v-else>
<el-menu-item <el-menu-item
:key="submenu.id" :key="submenu.id"
:index="submenu.name" :index="submenu.name"
:class="{ 'is-active': activeMenu === submenu.id }" :class="{ 'is-active': activeMenu === submenu.id }"
> >
<span>{{ submenu.name }}</span> <span>{{ submenu.name }}</span>
</el-menu-item> </el-menu-item>
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
</el-menu> </el-menu>
</template> </template>
<script> <script>
import { mapState } from "vuex"; import {mapState} from "vuex";
export default { export default {
data() { data() {
...@@ -77,16 +77,24 @@ export default { ...@@ -77,16 +77,24 @@ export default {
handler(val) { handler(val) {
// console.log("watch------ subNav", val); // console.log("watch------ subNav", val);
const result = this.treeFind( const result = this.treeFind(
val, val,
(item) => item.link === this.$route.path (item) => item.link === this.$route.path
); );
if (result) { if (result) {
console.log(result);
this.activeMenu = result.id; this.activeMenu = result.id;
} }
}, },
immediate: true, immediate: true,
}, },
$route(to, from) {
const result = this.treeFind(
this.subNav,
(item) => item.link === this.$route.path
);
if (result) {
this.activeMenu = result.id;
}
}
}, },
methods: { methods: {
treeFind(tree, func) { treeFind(tree, func) {
...@@ -147,7 +155,7 @@ export default { ...@@ -147,7 +155,7 @@ export default {
if (item.breadcrumb) { if (item.breadcrumb) {
this.$store.commit("system/SET_BREADCRUMB", item.breadcrumb); this.$store.commit("system/SET_BREADCRUMB", item.breadcrumb);
} }
this.$router.push({ path: item.link }); this.$router.push({path: item.link});
} }
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment