Skip to content

Commit

Permalink
fix: 第一个缓存页面加载时不触发 onActivated 钩子 (#214)
Browse files Browse the repository at this point in the history
Co-authored-by: pany <[email protected]>
  • Loading branch information
QC2168 and pany-ang authored Nov 8, 2024
1 parent ffb6cb3 commit 13a53cc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
11 changes: 6 additions & 5 deletions src/layouts/components/TagsView/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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)
})
</script>

Expand Down
4 changes: 2 additions & 2 deletions src/store/modules/tags-view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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) {
// 防止 query 参数丢失
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 })
}
}

Expand Down

0 comments on commit 13a53cc

Please sign in to comment.