Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gs1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
吴迪
gs1
Commits
b1bdd036
Commit
b1bdd036
authored
Dec 24, 2021
by
tang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: 监听路由变换,高亮导航
parent
e23b2794
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
22 deletions
+30
-22
SubNav.vue
src/views/comps/SubNav.vue
+30
-22
No files found.
src/views/comps/SubNav.vue
View file @
b1bdd036
<
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
});
}
}
},
},
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment