diff --git a/src/layouts/components/TagsView/index.vue b/src/layouts/components/TagsView/index.vue index a7178d81..0e14c324 100644 --- a/src/layouts/components/TagsView/index.vue +++ b/src/layouts/components/TagsView/index.vue @@ -65,7 +65,7 @@ const initTags = () => { affixTags = filterAffixTags(permissionStore.routes) for (const tag of affixTags) { // 必须含有 name 属性 - tag.name && tagsViewStore.addVisitedView(tag) + tag.name && tagsViewStore.addVisitedView(tag, true) } } @@ -153,12 +153,13 @@ watch(visible, (value) => { value ? document.body.addEventListener("click", closeMenu) : document.body.removeEventListener("click", closeMenu) }) +/** 监听路由变化 */ +listenerRouteChange((route) => { + addTags(route) +}, true) + onMounted(() => { initTags() - /** 监听路由变化 */ - listenerRouteChange(async (route) => { - addTags(route) - }, true) }) diff --git a/src/store/modules/tags-view.ts b/src/store/modules/tags-view.ts index 51194de8..db728d3b 100644 --- a/src/store/modules/tags-view.ts +++ b/src/store/modules/tags-view.ts @@ -18,7 +18,7 @@ export const useTagsViewStore = defineStore("tags-view", () => { }) //#region add - const addVisitedView = (view: TagView) => { + const addVisitedView = (view: TagView, isUnshift: boolean = false) => { // 检查是否已经存在相同的 visitedView const index = visitedViews.value.findIndex((v) => v.path === view.path) if (index !== -1) { @@ -26,7 +26,7 @@ export const useTagsViewStore = defineStore("tags-view", () => { visitedViews.value[index].fullPath !== view.fullPath && (visitedViews.value[index] = { ...view }) } else { // 添加新的 visitedView - visitedViews.value.push({ ...view }) + isUnshift ? visitedViews.value.unshift({ ...view }) : visitedViews.value.push({ ...view }) } }