diff --git a/src/hooks/web/useTagsView.ts b/src/hooks/web/useTagsView.ts index d236a1e..6d78d6c 100644 --- a/src/hooks/web/useTagsView.ts +++ b/src/hooks/web/useTagsView.ts @@ -47,12 +47,17 @@ export const useTagsView = () => { callback?.() } + const setTitle = (title: string) => { + tagsViewStore.setTitle(title) + } + return { closeAll, closeLeft, closeRight, closeOther, closeCurrent, - refreshPage + refreshPage, + setTitle } } diff --git a/src/router/index.ts b/src/router/index.ts index cccf263..a20413a 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -339,7 +339,8 @@ export const asyncRouterMap: AppRouteRecordRaw[] = [ meta: { hidden: true, title: t('router.details'), - canTo: true + canTo: true, + activeMenu: '/function/multiple-tabs' } } ] diff --git a/src/store/modules/tagsView.ts b/src/store/modules/tagsView.ts index 483687b..df511e1 100644 --- a/src/store/modules/tagsView.ts +++ b/src/store/modules/tagsView.ts @@ -140,6 +140,14 @@ export const useTagsViewStore = defineStore('tagsView', { // 设置当前选中的tag setSelectedTag(tag: RouteLocationNormalizedLoaded) { this.selectedTag = tag + }, + setTitle(title: string) { + for (const v of this.visitedViews) { + if (v.path === this.selectedTag?.path) { + v.meta.title = title + break + } + } } } }) diff --git a/src/views/Function/MultipleTabsDemo.vue b/src/views/Function/MultipleTabsDemo.vue index e8089bd..9421a9a 100644 --- a/src/views/Function/MultipleTabsDemo.vue +++ b/src/views/Function/MultipleTabsDemo.vue @@ -3,10 +3,15 @@ import { ContentWrap } from '@/components/ContentWrap' import { ElInput } from 'element-plus' import { ref } from 'vue' import { useRoute } from 'vue-router' +import { useTagsView } from '@/hooks/web/useTagsView' + +const { setTitle } = useTagsView() const { params } = useRoute() const val = ref(params.id as string) + +setTitle(`详情页-${val.value}`)