Skip to content

Commit c715d68

Browse files
authored
fix: update tab titles when switching language (#17)
1 parent a44e3cb commit c715d68

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

packages/business/layouts/src/basic/tabbar/use-tabs.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ import type {
55
RouteRecordNormalized,
66
} from 'vue-router';
77

8-
import { computed, watch } from 'vue';
8+
import { computed, ref, watch } from 'vue';
99
import { useRoute, useRouter } from 'vue-router';
1010

11-
import { $t } from '@vben/locales';
11+
import { $t, useI18n } from '@vben/locales';
1212
import {
1313
IcRoundClose,
1414
IcRoundMultipleStop,
@@ -33,8 +33,11 @@ function useTabs() {
3333
return route.path;
3434
});
3535

36-
const currentTabs = computed(() => {
37-
return tabsStore.getTabs;
36+
const { locale } = useI18n();
37+
const currentTabs =
38+
ref<(RouteLocationNormalized | RouteRecordNormalized)[]>();
39+
watch([() => tabsStore.getTabs, () => locale.value], ([tabs, _]) => {
40+
currentTabs.value = tabs.map((item) => wrapperTabLocale(item));
3841
});
3942

4043
/**
@@ -44,9 +47,6 @@ function useTabs() {
4447
const affixTabs = filterTree(router.getRoutes(), (route) => {
4548
return !!route.meta?.affixTab;
4649
});
47-
affixTabs.forEach((tab) => {
48-
Object.assign(tab, wrapperTabLocale(tab));
49-
});
5050
tabsStore.setAffixTabs(affixTabs);
5151
};
5252

@@ -83,7 +83,7 @@ function useTabs() {
8383
watch(
8484
() => route.path,
8585
() => {
86-
tabsStore.addTab(wrapperTabLocale(route) as RouteLocationNormalized);
86+
tabsStore.addTab(route as RouteLocationNormalized);
8787
},
8888
{ immediate: true },
8989
);

0 commit comments

Comments
 (0)