docs: update nuxt/content example

This commit is contained in:
Daniel Roe 2025-01-20 13:50:01 +00:00
parent 09c3f79eff
commit 5429876278
No known key found for this signature in database
GPG Key ID: 3714AB03996F442B

View File

@ -36,14 +36,24 @@ The module automatically loads and parses them.
## Render Content
To render content pages, add a [catch-all route](/docs/guide/directory-structure/pages/#catch-all-route) using the [`<ContentDoc>`](https://content.nuxt.com/components/content-doc) component:
To render content pages, add a [catch-all route](/docs/guide/directory-structure/pages/#catch-all-route) using the [`<ContentRenderer>`](https://content.nuxt.com/docs/components/content-renderer) component:
```vue [pages/[...slug\\].vue]
<script lang="ts" setup>
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => {
return queryCollection('content').path(route.path).first()
})
</script>
<template>
<main>
<!-- ContentDoc returns content for `$route.path` by default or you can pass a `path` prop -->
<ContentDoc />
</main>
<div>
<header><!-- ... --></header>
<ContentRenderer v-if="page" :value="page" />
<footer><!-- ... --></footer>
</div>
</template>
```