From 89ac6f4b4ade68caef8fb62ebbb7b720c4e5b132 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E6=95=8F=E5=8D=8E?= <180657@gree.com.cn>
Date: Sat, 14 Dec 2019 14:43:51 +0800
Subject: [PATCH 1/2] fix[TagsView]: fixed CachedView bug (PanJiaChen#406)
---
src/store/modules/tagsView.js | 18 ++++++++++++------
1 file changed, 12 insertions(+), 6 deletions(-)
diff --git a/src/store/modules/tagsView.js b/src/store/modules/tagsView.js
index 57e72421..30f46444 100644
--- a/src/store/modules/tagsView.js
+++ b/src/store/modules/tagsView.js
@@ -13,9 +13,13 @@ const mutations = {
)
},
ADD_CACHED_VIEW: (state, view) => {
- if (state.cachedViews.includes(view.name)) return
if (!view.meta.noCache) {
- state.cachedViews.push(view.name)
+ for (const matchedView of view.matched) {
+ const { name } = matchedView.components.default
+ if (name && state.cachedViews.indexOf(name) === -1) {
+ state.cachedViews.push(name)
+ }
+ }
}
},
@@ -28,8 +32,9 @@ const mutations = {
}
},
DEL_CACHED_VIEW: (state, view) => {
- const index = state.cachedViews.indexOf(view.name)
- index > -1 && state.cachedViews.splice(index, 1)
+ const deletedViewName = view.matched[view.matched.length - 1].components.default.name
+ const index = state.cachedViews.indexOf(deletedViewName)
+ state.cachedViews.splice(index, 1)
},
DEL_OTHERS_VISITED_VIEWS: (state, view) => {
@@ -38,9 +43,10 @@ const mutations = {
})
},
DEL_OTHERS_CACHED_VIEWS: (state, view) => {
- const index = state.cachedViews.indexOf(view.name)
+ const currentViewName = view.matched[view.matched.length - 1].components.default.name
+ const index = state.cachedViews.indexOf(currentViewName)
if (index > -1) {
- state.cachedViews = state.cachedViews.slice(index, index + 1)
+ state.cachedViews = view.matched.map(i => i.components.default.name)
} else {
// if index = -1, there is no cached tags
state.cachedViews = []
From 169105358cbbd0014ca5f5f7ac1b37df2543d10f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E6=A2=81=E6=95=8F=E5=8D=8E?= <180657@gree.com.cn>
Date: Sat, 14 Dec 2019 15:05:47 +0800
Subject: [PATCH 2/2] feat[nested]:add cache nested router demo
---
src/views/nested/menu1/index.vue | 14 ++++++++++++++
src/views/nested/menu1/menu1-2/index.vue | 18 +++++++++++++++++-
.../nested/menu1/menu1-2/menu1-2-1/index.vue | 17 +++++++++++++++--
.../nested/menu1/menu1-2/menu1-2-2/index.vue | 17 +++++++++++++++--
4 files changed, 61 insertions(+), 5 deletions(-)
diff --git a/src/views/nested/menu1/index.vue b/src/views/nested/menu1/index.vue
index 30cb6701..1846c546 100644
--- a/src/views/nested/menu1/index.vue
+++ b/src/views/nested/menu1/index.vue
@@ -5,3 +5,17 @@
+
+
diff --git a/src/views/nested/menu1/menu1-2/index.vue b/src/views/nested/menu1/menu1-2/index.vue
index 0c86276e..39b24a07 100644
--- a/src/views/nested/menu1/menu1-2/index.vue
+++ b/src/views/nested/menu1/menu1-2/index.vue
@@ -1,7 +1,23 @@
-
+
+
+
+
+
diff --git a/src/views/nested/menu1/menu1-2/menu1-2-1/index.vue b/src/views/nested/menu1/menu1-2/menu1-2-1/index.vue
index f87d88f4..395dd40c 100644
--- a/src/views/nested/menu1/menu1-2/menu1-2-1/index.vue
+++ b/src/views/nested/menu1/menu1-2/menu1-2-1/index.vue
@@ -1,5 +1,18 @@
-
+
-
+
+
+
+
+
diff --git a/src/views/nested/menu1/menu1-2/menu1-2-2/index.vue b/src/views/nested/menu1/menu1-2/menu1-2-2/index.vue
index d88789f2..959e9a92 100644
--- a/src/views/nested/menu1/menu1-2/menu1-2-2/index.vue
+++ b/src/views/nested/menu1/menu1-2/menu1-2-2/index.vue
@@ -1,5 +1,18 @@
-
+
-
+
+
+
+
+