Nuxt Content 会读取你项目中的 content/ 目录 并解析 .md、.yml、.csv 和 .json 文件,为你的应用创建一个基于文件的 CMS。
通过一条命令在你的项目中安装 @nuxt/content 模块并将其添加到 nuxt.config.ts:
npx nuxt module add content
将你的 Markdown 文件放到 content/ 目录中:
# Hello Content
该模块会自动加载并解析它们。
要渲染内容页面,使用 <ContentRenderer> 组件添加一个 catch-all 路由:
<script lang="ts" setup>
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () => {
return queryCollection('content').path(route.path).first()
})
</script>
<template>
<div>
<header><!-- ... --></header>
<ContentRenderer
v-if="page"
:value="page"
/>
<footer><!-- ... --></footer>
</div>
</template>