Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd431de0

Browse files
committed
perf keep-alive in nested route
1 parent6f2a7ce commitd431de0

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed

‎src/store/modules/tagsView.js

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,21 @@ const tagsView = {
66
mutations:{
77
ADD_VISITED_VIEWS:(state,view)=>{
88
if(state.visitedViews.some(v=>v.path===view.path))return
9-
state.visitedViews.push({
10-
name:view.name,
11-
path:view.path,
12-
title:view.meta.title||'no-name'
13-
})
9+
10+
if(view.showInVisitedViews){
11+
state.visitedViews.push({
12+
name:view.name,
13+
path:view.path,
14+
title:view.meta.title||'no-name'
15+
})
16+
}
17+
1418
if(!view.meta.noCache){
15-
state.cachedViews.push(view.name)
19+
constcachedViews=[...state.cachedViews]
20+
cachedViews.push(view.name)
21+
state.cachedViews=Array.from(newSet([...cachedViews]))
1622
}
23+
console.log(state.cachedViews)
1724
},
1825
DEL_VISITED_VIEWS:(state,view)=>{
1926
for(const[i,v]ofstate.visitedViews.entries()){

‎src/views/example/table/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<script>
1010
exportdefault {
11-
name:'TableMain',
11+
name:'Table',
1212
computed: {
1313
cachedViews() {
1414
returnthis.$store.state.tagsView.cachedViews

‎src/views/layout/components/TagsView.vue

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,29 @@ export default {
5252
methods: {
5353
generateTitle,// generateTitle by vue-i18n
5454
generateRoute() {
55-
if (this.$route.name) {
56-
returnthis.$route
55+
let matched= [...this.$route.matched]
56+
matched.splice(0,1)
57+
matched=matched.filter(item=>item.name)
58+
if (matched) {
59+
return matched
5760
}
5861
returnfalse
5962
},
6063
isActive(route) {
6164
returnroute.path===this.$route.path||route.name===this.$route.name
6265
},
6366
addViewTags() {
64-
constroute=this.generateRoute()
65-
if (!route) {
67+
constroutes=this.generateRoute()
68+
if (!routes) {
6669
returnfalse
6770
}
68-
this.$store.dispatch('addVisitedViews', route)
71+
constlength=routes.length
72+
routes.forEach((item,index)=> {
73+
if (index=== length-1) {
74+
item.showInVisitedViews=true
75+
}
76+
this.$store.dispatch('addVisitedViews', item)
77+
})
6978
},
7079
moveToCurrentTag() {
7180
consttags=this.$refs.tag

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp