DocsToc
A sticky Table of Contents with customizable slots.
Usage
<script setup>
const { data: page } = await useAsyncData(route.path, () => queryContent(route.path).findOne())
</script>
<template>
<UDocsToc :links="page.body.toc.links" />
</template>
You'll usually use this component in the #right
slot of a Page:
pages/[...slug].vue
<script setup lang="ts">
import { withoutTrailingSlash } from 'ufo'
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => queryContent(route.path).findOne())
if (!page.value) {
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}
const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
return queryContent()
.where({ _extension: 'md', navigation: { $ne: false } })
.only(['title', 'description', '_path'])
.findSurround(withoutTrailingSlash(route.path))
})
</script>
<template>
<UPage>
<UPageHeader :title="page.title" :description="page.description" :links="page.links" />
<UPageBody prose>
<ContentRenderer v-if="page.body" :value="page" />
<hr v-if="surround?.length">
<UDocsSurround :surround="surround" />
</UPageBody>
<template v-if="page.body?.toc?.links?.length" #right>
<UDocsToc :links="page.body.toc.links" />
</template>
</UPage>
</template>
Slots
top
{}
bottom
{}
Props
ui
any
{}
links
TocLink[]
[]
title
string
"Table of Contents"