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) affixTags = filterAffixTags(permissionStore.routes)
for (const tag of affixTags) { for (const tag of affixTags) {
// name // 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) value ? document.body.addEventListener("click", closeMenu) : document.body.removeEventListener("click", closeMenu)
}) })
/** 监听路由变化 */
listenerRouteChange((route) => {
addTags(route)
}, true)
onMounted(() => { onMounted(() => {
initTags() initTags()
/** 监听路由变化 */
listenerRouteChange(async (route) => {
addTags(route)
}, true)
}) })
</script> </script>

View File

@ -18,7 +18,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
}) })
//#region add //#region add
const addVisitedView = (view: TagView) => { const addVisitedView = (view: TagView, isUnshift: boolean = false) => {
// 检查是否已经存在相同的 visitedView // 检查是否已经存在相同的 visitedView
const index = visitedViews.value.findIndex((v) => v.path === view.path) const index = visitedViews.value.findIndex((v) => v.path === view.path)
if (index !== -1) { if (index !== -1) {
@ -26,7 +26,7 @@ export const useTagsViewStore = defineStore("tags-view", () => {
visitedViews.value[index].fullPath !== view.fullPath && (visitedViews.value[index] = { ...view }) visitedViews.value[index].fullPath !== view.fullPath && (visitedViews.value[index] = { ...view })
} else { } else {
// 添加新的 visitedView // 添加新的 visitedView
visitedViews.value.push({ ...view }) isUnshift ? visitedViews.value.unshift({ ...view }) : visitedViews.value.push({ ...view })
} }
} }