fix: 缓存标签栏数据时,删除不必要的属性,防止 JSON.stringify 处理到循环引用

This commit is contained in:
pany 2023-06-30 18:05:30 +08:00
parent e2ebc1da85
commit c3ad3c0ce1

View File

@ -43,6 +43,11 @@ export const getVisitedViews = () => {
return JSON.parse(json ?? "[]") as TagView[] return JSON.parse(json ?? "[]") as TagView[]
} }
export const setVisitedViews = (views: TagView[]) => { export const setVisitedViews = (views: TagView[]) => {
views.forEach((view) => {
// 删除不必要的属性,防止 JSON.stringify 处理到循环引用
delete view.matched
delete view.redirectedFrom
})
localStorage.setItem(CacheKey.VISITED_VIEWS, JSON.stringify(views)) localStorage.setItem(CacheKey.VISITED_VIEWS, JSON.stringify(views))
} }
export const getCachedViews = () => { export const getCachedViews = () => {