fix: update tab titles when switching language (#17)

pull/48/MERGE
Li Kui 2024-07-05 10:04:16 +08:00 committed by GitHub
parent a44e3cbc33
commit c715d68dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 8 additions and 8 deletions

View File

@ -5,10 +5,10 @@ import type {
RouteRecordNormalized,
} from 'vue-router';
import { computed, watch } from 'vue';
import { computed, ref, watch } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { $t } from '@vben/locales';
import { $t, useI18n } from '@vben/locales';
import {
IcRoundClose,
IcRoundMultipleStop,
@ -33,8 +33,11 @@ function useTabs() {
return route.path;
});
const currentTabs = computed(() => {
return tabsStore.getTabs;
const { locale } = useI18n();
const currentTabs =
ref<(RouteLocationNormalized | RouteRecordNormalized)[]>();
watch([() => tabsStore.getTabs, () => locale.value], ([tabs, _]) => {
currentTabs.value = tabs.map((item) => wrapperTabLocale(item));
});
/**
@ -44,9 +47,6 @@ function useTabs() {
const affixTabs = filterTree(router.getRoutes(), (route) => {
return !!route.meta?.affixTab;
});
affixTabs.forEach((tab) => {
Object.assign(tab, wrapperTabLocale(tab));
});
tabsStore.setAffixTabs(affixTabs);
};
@ -83,7 +83,7 @@ function useTabs() {
watch(
() => route.path,
() => {
tabsStore.addTab(wrapperTabLocale(route) as RouteLocationNormalized);
tabsStore.addTab(route as RouteLocationNormalized);
},
{ immediate: true },
);