From 08c9a224b7b5ceaa5cb0d012ce4f9790cd6ce7a4 Mon Sep 17 00:00:00 2001 From: toesbieya <1647775459@qq.com> Date: Mon, 31 Aug 2020 18:18:00 +0800 Subject: [PATCH] =?UTF-8?q?KeepRouterViewAlive=E5=B0=8F=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Main/component/KeepRouterViewAlive.vue | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/vue/src/layout/component/Main/component/KeepRouterViewAlive.vue b/vue/src/layout/component/Main/component/KeepRouterViewAlive.vue index cd4defb..641eb93 100644 --- a/vue/src/layout/component/Main/component/KeepRouterViewAlive.vue +++ b/vue/src/layout/component/Main/component/KeepRouterViewAlive.vue @@ -17,11 +17,9 @@ function getComponentName(opts) { return opts && (opts.Ctor.options.name || opts.tag) } -function pruneCacheEntry(cache, key, current) { +function removeCache(cache, key) { const cached = cache[key] - if (cached && (!current || cached.tag !== current.tag)) { - cached.componentInstance && cached.componentInstance.$destroy() - } + cached && cached.componentInstance && cached.componentInstance.$destroy() delete cache[key] } @@ -47,12 +45,12 @@ export default { include: { deep: true, handler(val) { - const {cache, $route, _vnode} = this + const {cache, $route} = this for (const key of Object.keys(cache)) { const cachedNode = cache[key] const name = getCacheKey($route, cachedNode.componentOptions) - if (name && !val.includes(name)) { - pruneCacheEntry(cache, key, _vnode) + if (!val || !val.includes(name)) { + removeCache(cache, key) } } } @@ -65,7 +63,7 @@ export default { beforeDestroy() { for (const key of Object.keys(this.cache)) { - pruneCacheEntry(this.cache, key) + removeCache(this.cache, key) } },