nuxt dev) isn't running and remove any package lock files (package-lock.json, yarn.lock, or pnpm-lock.yaml)- "nuxt": "latest"
+ "nuxt": "^3.0.0"
- "@nuxt/content": "^1.15.1"
+ "@nuxt/content": "^2.0.0"
npm install
The global components directory for Nuxt Content v2 is now ~/components/content.
- components/global
+ components/content
There is no global $content variable, instead you can use queryContent composable to fetch contents.
- const posts = await this.$content('/blog', { deep: true }).only(['title']).fetch()
+ const { data: posts } = await useAsyncData('posts-list', () => queryContent('/blog').only(['title']).find())
queryContent provides same utilities as legacy $content with some improvements:
fetch dropped in favor of new find utilssurround dropped in favor of findSurroundwhere utility can be chainedqueryContent()
.where({ /* first step conditions */ })
.where({ /* second step conditions */ })
.find()
search utility for full text search.const doc = await getContentDocument(post.id)
fetchContentNavigation utility is designed to provide a tree of items based on the content/ directory structure.<NuxtContent> component removed in favor of a <ContentRenderer> component.
<ContentDoc> component receives a document path and then fetches and renders the document.
<script setup lang="ts">
const route = useRoute()
const { data } = await useAsyncData('get-document', () => queryContent(route.path).findOne())
</script>
<template>
<ContentRenderer :value="data" />
</template>
You can go even faster if you know that route.path will be the same as your content files, use the <ContentDoc> component:
<template>
<ContentDoc />
</template>
The <ContentDoc> component will fetch the document for the current route path and use <ContentRenderer> to render it.
| Feature / Version | Content v1 | Content v2 |
|---|---|---|
| Nuxt Version | nuxt@2.x | nuxt@3.x |
| Supported files | .md, .yaml, .yml, .csv, .json, .json5, .xml | .md, .yaml, .yml, .csv, .json, .json5 |
| Full text search | ✅ | ❌ |
| Reactive Composables | ❌ | ✅ |
| FrontMatter | ✅ | ✅ |
| Excerpt | ✅ | ✅ |
| Table Of Contents | ✅ | ✅ |
| MDC Components syntax | ❌ | ✅ |
| Multi Source | ❌ | ✅ |
| Locale Support | ❌ | ✅ |
| Content Navigation | ❌ | ✅ |
[
{
"title": "Edge Channel",
"path": "/content-v2/get-started/edge-channel",
"stem": "content-v2/1.get-started/4.edge-channel",
"description": "Nuxt Content is landing commits, improvements, and bug fixes every day. You can opt-in to test them earlier before the next release."
},
{
"title": "Content Directory",
"path": "/content-v2/usage/content-directory",
"stem": "content-v2/2.usage/1.content-directory",
"description": "The Content module parses .md and .yaml files inside the content/ directory and provides paths according to the directory structure."
}
]