Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

处理每切换一次页面就增加一条sidebarItems数据的问题 #326

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions themes/theme-default/src/client/composables/useSidebarItems.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,12 @@ export type HeadersRef = Ref<MenuItem[]>
export const headersRef: HeadersRef = ref([])

export const setupHeaders = (): void => {
const router = useRouter()
const themeLocale = useThemeLocaleData()
const frontmatter = usePageFrontmatter<DefaultThemeNormalPageFrontmatter>()
const levels = computed(
() => frontmatter.value.sidebarDepth ?? themeLocale.value.sidebarDepth ?? 2,
)

router.beforeEach((to, from) => {
if (to.path !== from.path) {
headersRef.value = []
}
})

const updateHeaders = (): void => {
if (levels.value <= 0) {
headersRef.value = []
Expand Down Expand Up @@ -229,6 +222,7 @@ export const setupSidebarItems = (): void => {
>()
const page = usePageData()
const route = useRoute()
const router = useRouter()
const routeLocale = useRouteLocale()
const headers = useHeaders()

Expand All @@ -250,4 +244,10 @@ export const setupSidebarItems = (): void => {
),
)
provide(sidebarItemsSymbol, sidebarItems)

router.beforeEach((to, from) => {
if (to.path !== from.path) {
headersRef.value = []
}
})
}