For repositories using Nuxt 3 + Vue 3 + TypeScript.
Standardize the engineering practices of SSR/SSG rendering mode, combined API, automatic import, data acquisition, routing middleware and module plug-ins in the Nuxt 3 project to ensure conventional development and type safety.
window or document.useFetch / useAsyncData is used first, and the hydration consistency is checked.text
├── app.vue # Root component
├── nuxt.config.ts # Nuxt configuration
│
├── pages/ # File-based routing
│ ├── index.vue # /
│ ├── login.vue # /login
│ ├── dashboard/
│ │ ├── index.vue # /dashboard
│ │ └── users/
│ │ ├── index.vue # /dashboard/users
│ │ └── [id].vue # /dashboard/users/:id
│ └── [...slug].vue # Capture all
│
├── layouts/ # layout
│ ├── default.vue
│ └── auth.vue
│
├── components/ # Automatically import components
│ ├── Button/
│ │ └── Button.vue
│ └── AppHeader.vue
│
├── composables/ # Combined functions (automatically imported)
│ ├── useAuth.ts
│ └── useFetch.ts
│
├── server/ # Server API
│ ├── api/ # API routing
│ │ └── users/
│ │ └── index.get.ts
│ ├── middleware/ # Server-side middleware
│ └── utils/ # Server-side tools
│
├── plugins/ # Plug-in
│ └── i18n.client.ts
│
├── middleware/ # Routing middleware
│ └── auth.ts
│
├── public/ # Static resources
├── assets/ # Resources to be built
└── types/ # Type definition
ModeConfigurationDescriptionSSRDefaultssr: trueSSGnuxt generatePre-render all pagesSPAssr: falsePure client-side renderingts
// nuxt.config.ts
export default defineNuxtConfig({
ssr: true, // or false
});
useFetch / useAsyncData: server + client, automatic deduplication$fetch: direct request, suitable for server or one-time calluseLazyAsyncData: does not block navigation, suitable for non-first screensetup causing hydration mismatchpages/[id].vue, [...slug].vuelayout option or layouts/default.vue defaultpages/parent/child.vue needs to be combined with NuxtPagemiddleware/definePageMeta({ middleware: ['auth'] })router.middleware of nuxt.config.tsserver/middleware/plugins/*.ts, supports .client, .server suffixesmodules/ or node_modules, in nuxt.config modules: []window or documentuseState to share stateNuxtImg for images and NuxtLink for linksawait at the top level of setup which will cause blocking. Use useAsyncData / useFetch firstpages/ conventional routing, and dynamic routing is correctly configurednuxt.config.ts configuration is clearuseFetch / useAsyncData, automatic deduplication and hydration