Skip to content

Commit

Permalink
fix(forum): 优化话题数据跳转时的缓存处理
Browse files Browse the repository at this point in the history
  • Loading branch information
jiazengp committed Jan 17, 2025
1 parent a5560ca commit 8d36eb9
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/composables/sharedTopicInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ export const SHARED_TOPIC_INFO_KEY = 'topic-info'

export const useSharedTopicInfo = (topic?: ForumAPI.Topic) => {
if (import.meta.env.SSR) return computed(() => null)
const data = sessionStorage.getItem(SHARED_TOPIC_INFO_KEY)

return computed<ForumAPI.Topic>(() => {
const data = sessionStorage.getItem(SHARED_TOPIC_INFO_KEY)
if (data) {
sessionStorage.removeItem(SHARED_TOPIC_INFO_KEY)
return JSON.parse(data)
}
sessionStorage.setItem(SHARED_TOPIC_INFO_KEY, JSON.stringify(topic))
return topic
})
if (data && topic === undefined) {
sessionStorage.removeItem(SHARED_TOPIC_INFO_KEY)
return computed(() => JSON.parse(data))
}

if (!topic) return computed(() => null)
sessionStorage.setItem(SHARED_TOPIC_INFO_KEY, JSON.stringify(topic))
return computed<ForumAPI.Topic>(() => topic)
}

0 comments on commit 8d36eb9

Please sign in to comment.