fix keep-alive

This commit is contained in:
liangzhiyuan001 2022-09-15 15:51:13 +08:00
parent 7217ef5a56
commit 32f6c65701
2 changed files with 12 additions and 12 deletions

View File

@ -13,12 +13,11 @@
<script>
import { defineComponent, h } from 'vue';
import store from '@/store';
import { mapState } from 'pinia';
import { wrapperMap } from '@/store/modules/tagsView';
export default defineComponent({
name: 'AppMain',
computed: {
...mapState(store.tagsView, ['wrapperMap']),
cachedViews() {
return store.tagsView().cachedViews;
}
@ -31,8 +30,8 @@ export default defineComponent({
// .
// keep-alive include .
const wrapperName = route.name;
if (this.wrapperMap.has(wrapperName)) {
wrapper = this.wrapperMap.get(wrapperName);
if (wrapperMap.has(wrapperName)) {
wrapper = wrapperMap.get(wrapperName);
} else {
wrapper = {
name: wrapperName,
@ -40,7 +39,7 @@ export default defineComponent({
return h('div', { className: 'vaf-page-wrapper' }, component);
}
};
this.wrapperMap.set(wrapperName, wrapper);
wrapperMap.set(wrapperName, wrapper);
}
return h(wrapper);
}

View File

@ -1,9 +1,10 @@
import { defineStore } from 'pinia';
export const wrapperMap = new Map();
const getDefaultState = () => ({
visitedViews: [],
cachedViews: [],
wrapperMap: new Map()
cachedViews: []
});
const getters = {};
@ -42,8 +43,8 @@ const actions = {
delCachedView(view) {
const index = this.cachedViews.indexOf(view.name);
index > -1 && this.cachedViews.splice(index, 1);
if (this.wrapperMap.has(view.name)) {
this.wrapperMap.delete(view.name);
if (wrapperMap.has(view.name)) {
wrapperMap.delete(view.name);
}
},
@ -64,9 +65,9 @@ const actions = {
// if index = -1, there is no cached tags
this.cachedViews = [];
}
this.wrapperMap.forEach((value, key) => {
wrapperMap.forEach((value, key) => {
if (view.name !== key) {
this.wrapperMap.delete(key);
wrapperMap.delete(key);
}
});
},
@ -82,7 +83,7 @@ const actions = {
},
delAllCachedViews() {
this.cachedViews = [];
this.wrapperMap.clear();
wrapperMap.clear();
},
updateVisitedView(view) {