fix: fix routing switch, tab is not activated

This commit is contained in:
nebv
2020-10-13 01:39:56 +08:00
parent 177010bf8b
commit beb4c3a37f
8 changed files with 42 additions and 26 deletions

View File

@@ -3,6 +3,9 @@ import { PageEnum } from '/@/enums/pageEnum';
import { TabItem, tabStore } from '/@/store/modules/tab';
import { appStore } from '/@/store/modules/app';
import router from '/@/router';
import { ref } from 'vue';
const activeKeyRef = ref<string>('');
type Fn = () => void;
type RouteFn = (tabItem: TabItem) => void;
@@ -70,12 +73,13 @@ export function useTabs() {
closeOther: () => canIUseFn() && closeOther(tabStore.getCurrentTab),
closeCurrent: () => canIUseFn() && closeCurrent(tabStore.getCurrentTab),
resetCache: () => canIUseFn() && resetCache(),
addTab: (path: PageEnum, goTo = false) => {
addTab: (path: PageEnum, goTo = false, replace = false) => {
useTimeout(() => {
tabStore.addTabByPathAction(path);
}, 0);
goTo && router.push(path);
activeKeyRef.value = path;
goTo && replace ? router.replace : router.push(path);
},
activeKeyRef,
};
}