📦 Nuxt Project Standard — Nuxt工具
v1.0.0Nuxt 3 项目规范,涵盖目录结构、SSR/SSG、组合式 API、数据获取、路由、中间件、插件与模块。当用户在 Nuxt 3 项目中创建、修改页面或模块时自动激活。
0· 111·0 当前·0 累计
安全扫描
OpenClaw
安全
high confidenceThis skill is an instruction-only Nuxt 3 styleguide and its requested resources and runtime instructions are consistent with that purpose.
安全有层次,运行前请审查代码。
运行时依赖
无特殊依赖
版本
latestv1.0.02026/3/27
- Initial release of Nuxt 3 project standard. - Provides guidelines for directory structure, SSR/SSG configuration, composition API usage, data fetching, routing, middleware, plugins, and modules. - Aimed at Nuxt 3 + Vue 3 + TypeScript repositories. - Automatically activates when creating or modifying pages or modules in a Nuxt 3 project.
● 无害
安装命令
点击复制官方npx clawhub@latest install nuxt-project-standard
🇨🇳 镜像加速npx clawhub@latest install nuxt-project-standard --registry https://cn.longxiaskill.com
技能文档
适用于使用 Nuxt 3 + Vue 3 + TypeScript 的仓库。
适用场景
- 新建或修改页面
- 配置 SSR / SSG(静态生成)
- 使用组合式 API、数据获取
- 路由、中间件、插件与模块
项目结构
├── app.vue # 根组件
├── nuxt.config.ts # Nuxt 配置
│
├── pages/ # 基于文件的路由
│ ├── index.vue # /
│ ├── login.vue # /login
│ ├── dashboard/
│ │ ├── index.vue # /dashboard
│ │ └── users/
│ │ ├── index.vue # /dashboard/users
│ │ └── [id].vue # /dashboard/users/:id
│ └── [...slug].vue # 捕获所有
│
├── layouts/ # 布局
│ ├── default.vue
│ └── auth.vue
│
├── components/ # 自动导入组件
│ ├── Button/
│ │ └── Button.vue
│ └── AppHeader.vue
│
├── composables/ # 组合式函数(自动导入)
│ ├── useAuth.ts
│ └── useFetch.ts
│
├── server/ # 服务端 API
│ ├── api/ # API 路由
│ │ └── users/
│ │ └── index.get.ts
│ ├── middleware/ # 服务端中间件
│ └── utils/ # 服务端工具
│
├── plugins/ # 插件
│ └── i18n.client.ts
│
├── middleware/ # 路由中间件
│ └── auth.ts
│
├── public/ # 静态资源
├── assets/ # 需构建的资源
└── types/ # 类型定义
渲染模式
| 模式 | 配置 | 说明 |
|---|---|---|
| SSR | 默认 | ssr: true |
| SSG | nuxt generate | 预渲染所有页面 |
| SPA | ssr: false | 纯客户端渲染 |
// nuxt.config.ts
export default defineNuxtConfig({
ssr: true, // 或 false
})
数据获取
useFetch/useAsyncData:服务端 + 客户端,自动去重$获取:直接请求,适合服务端或一次性调用useLazyAsyncData:不阻塞导航,适合非首屏- 避免在
setup顶层混用同步/异步逻辑导致水合不匹配
路由与布局
pages/下文件自动生成路由- 动态路由:
[id].vue、[...slug].vue - 布局:
布局选项或layouts/默认.vue默认 - 嵌套路由:
pages/parent/child.vue需配合NuxtPage
中间件
中间件/下文件自动注册- 页面级:
definePageMeta({ 中间件: ['auth'] }) - 全局:
nuxt.配置.ts的router.中间件 - 服务端中间件:
server/中间件/
插件与模块
- 插件:
plugins/*.ts,支持.client、.server后缀 - 模块:
modules/或node_modules,在nuxt.配置中modules: []
强约束
- 服务端可访问的代码不要依赖
window、document - 使用
useState共享状态时注意 SSR 序列化 - 图片使用
NuxtImg,链接使用NuxtLink - 避免在
setup顶层使用等待导致阻塞,优先用useAsyncData/useFetch
数据来源:ClawHub ↗ · 中文优化:龙虾技能库