logo
0
0
WeChat Login

Nuxt Minimal Starter

Look at the Nuxt documentation to learn more.

Setup

Make sure to install dependencies:

# npm
npm install

# pnpm
pnpm install

# yarn
yarn install

# bun
bun install

Development Server

Start the development server on http://localhost:3000:

# npm
npm run dev

# pnpm
pnpm dev

# yarn
yarn dev

# bun
bun run dev

Production

Build the application for production:

# npm
npm run build

# pnpm
pnpm build

# yarn
yarn build

# bun
bun run build

Locally preview production build:

# npm
npm run preview

# pnpm
pnpm preview

# yarn
yarn preview

# bun
bun run preview

Check out the deployment documentation for more information.

可能遇到的问题和解决方案

问题 1:Top-level await 表达式错误

问题描述:app/pages/index.vue 文件中出现以下错误:

[Vetur Error] Line 2: Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

问题代码:

<script setup lang="ts">
const { data: posts } = await useAsyncData('blog', () => queryCollection('blog').all())
</script>

解决方案:

  1. 检查 tsconfig.json 文件中的配置
  2. 确保 module 选项设置为 'es2022''esnext''system''node16''nodenext'
  3. 确保 target 选项设置为 'es2017' 或更高版本

推荐的 tsconfig.json 配置:

{
  "compilerOptions": {
    "module": "esnext",
    "target": "es2017",
    "moduleResolution": "node"
  }
}

问题 2:Cannot find name 'queryCollection' 错误

问题描述:app/pages/index.vue 文件中出现以下错误:

[Vetur Error] Line 2: Cannot find name 'queryCollection'.

问题代码:

<script setup lang="ts">
const { data: posts } = await useAsyncData('blog', () => queryCollection('blog').all())
</script>

解决方案:

  1. 确保已安装并配置了 Nuxt Content 模块
  2. nuxt.config.ts 中添加 Nuxt Content 配置
  3. 检查 content.config.ts 文件是否正确配置

安装 Nuxt Content:

npm install @nuxt/content

nuxt.config.ts 配置:

export default defineNuxtConfig({
  modules: ['@nuxt/content'],
  content: {
    // 配置选项
  }
})

vscode 中禁用 Vetur,启用 Volar 插件


通用调试建议

  1. 重启开发服务器:在修改配置文件后,重启 npm run dev
  2. 清除缓存:删除 .nuxt 目录后重新启动
  3. 检查依赖:确保所有依赖都已正确安装
  4. 查看控制台:检查浏览器控制台和终端输出中的详细错误信息

About

Nuxt下的资讯、文章模板的blog

Language
Vue49%
TypeScript48%
CSS2.1%
JavaScript1%