Template
1
0
mirror of https://github.com/un-pany/v3-admin-vite.git synced 2025-04-21 03:19:19 +08:00

fix: 第一个缓存页面加载时不触发 onActivated 钩子 (#214)

Co-authored-by: pany <939630029@qq.com>
This commit is contained in:
_island 2024-11-08 19:40:42 +08:00 committed by GitHub
parent ffb6cb3a11
commit 13a53cc994
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 7 deletions

View File

@ -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)
})
</script>

View File

@ -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 })
}
}