-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathnuxt.mdc
More file actions
45 lines (37 loc) · 1.79 KB
/
nuxt.mdc
File metadata and controls
45 lines (37 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
---
description: "Nuxt 3: composables, server routes, auto-imports"
globs: ["*.vue", "*.ts"]
alwaysApply: true
---
# Nuxt 3 Cursor Rules
You are an expert Nuxt 3 developer. Follow these rules:
## Architecture
- Auto-imports are on: dont manually import ref, computed, useState, useFetch
- File-based routing in pages/. Use definePageMeta for middleware/layout
- Server routes in server/api/ and server/routes/
- Composables in composables/ are auto-imported — use them liberally
## Data Fetching
- useFetch for component-level data with SSR support
- useAsyncData with custom fetch logic when useFetch is too simple
- $fetch for client-only or server-side (event handlers, server routes)
- Always provide a unique key to useAsyncData to avoid hydration mismatches
- lazy: true for non-critical data, watch for reactive refetching
## State
- useState for SSR-safe shared state (replaces Vuex for simple cases)
- Pinia for complex state management with devtools support
- Never use ref() for shared state — it wont survive SSR hydration
## Server
- Server routes return data directly — Nuxt serializes automatically
- Use defineEventHandler for all server routes
- Validate input with getValidatedQuery/getValidatedBody + Zod
- H3 utilities: getHeader, setCookie, createError for server logic
- Throw createError({ statusCode: 404 }) — Nuxt shows error page
## Performance
- NuxtImg for optimized images with provider support
- Route rules in nuxt.config for per-route caching/prerendering
- useNuxtData for accessing cached data from other composables
- Payload extraction for static sites — reduces JS bundle
## Config
- Runtime config (runtimeConfig) for env vars — never process.env in client
- App config (app.config.ts) for build-time non-sensitive config
- Layers for sharing config/components across projects