diff --git a/src/hooks/web/useTabs.ts b/src/hooks/web/useTabs.ts
index b75cb361f..68659e5d2 100644
--- a/src/hooks/web/useTabs.ts
+++ b/src/hooks/web/useTabs.ts
@@ -37,6 +37,15 @@ export function useTabs(_router?: Router) {
return tabStore.getTabList.find((item) => item.path === route.path)!;
}
+ async function updateTabTitle(title: string, tab?: RouteLocationNormalized) {
+ const canIUse = canIUseTabs;
+ if (!canIUse) {
+ return;
+ }
+ const targetTab = tab || getCurrentTab();
+ await tabStore.setTabTitle(title, targetTab);
+ }
+
async function handleTabAction(action: TableActionEnum, tab?: RouteLocationNormalized) {
const canIUse = canIUseTabs;
if (!canIUse) {
@@ -81,5 +90,6 @@ export function useTabs(_router?: Router) {
close: (tab?: RouteLocationNormalized) => {
handleTabAction(TableActionEnum.CLOSE, tab);
},
+ setTitle: (title: string, tab?: RouteLocationNormalized) => updateTabTitle(title, tab),
};
}
diff --git a/src/store/modules/multipleTab.ts b/src/store/modules/multipleTab.ts
index 848b7b286..08862fa63 100644
--- a/src/store/modules/multipleTab.ts
+++ b/src/store/modules/multipleTab.ts
@@ -286,6 +286,17 @@ export const useMultipleTabStore = defineStore({
async bulkCloseTabs(pathList: string[]) {
this.tabList = this.tabList.filter((item) => !pathList.includes(item.fullPath));
},
+
+ /**
+ * Set tab's title
+ */
+ async setTabTitle(title: string, route: RouteLocationNormalized) {
+ const findTab = this.getTabList.find((item) => item === route);
+ if (findTab) {
+ findTab.meta.title = title;
+ await this.updateCacheTab();
+ }
+ },
},
});
diff --git a/src/views/demo/feat/tabs/index.vue b/src/views/demo/feat/tabs/index.vue
index 8c50a236e..3a837c15d 100644
--- a/src/views/demo/feat/tabs/index.vue
+++ b/src/views/demo/feat/tabs/index.vue
@@ -1,7 +1,11 @@
-
+
+
+ 设置Tab标题
+
+
@@ -15,18 +19,28 @@