# Nuxt & Vue Coding Standards This guide outlines code style, architectural conventions, and implementation practices for Nuxt 4 and Vue 3 in the CineK (kr-phim) project. --- ## 1. Vue 3 & Composition API - **Single File Components (SFC)**: Always use the ` ``` --- ## 2. Nuxt 4 Directory Structure & Organization All code must align with the Nuxt 4 structure under the `/app` folder: - **`app/pages/`**: File-system based routing. Keep files structured logically (e.g., `app/pages/admin/phim/index.vue`). - **`app/components/`**: Place reusable components here. Nuxt auto-imports all components inside this folder. Use PascalCase or kebab-case when using them in templates (e.g., ``). - **`app/composables/`**: Store custom reactive functions here (e.g. `useAuth.ts`). - **`app/layouts/`**: Core layouts (e.g., `admin.vue`). - **`app/utils/`**: Helper utility functions. - **`server/`**: API endpoints, middleware, and database operations. --- ## 3. Data Fetching Guidelines Nuxt 4 provides specific wrappers for network requests. Use them properly to maintain SSR compatibility: - **`useFetch`**: Use for fetching data during initial page load/rendering. Supports automatic refresh and refetching. ```typescript const { data: movies, pending, error } = await useFetch('/api/movies', { query: { limit: 10 } }) ``` - **`$fetch`**: Use for event-driven requests, client-side actions, form submissions, and mutation events. ```typescript async function handleSubmit() { await $fetch('/api/movies', { method: 'POST', body: { name: 'New Movie' } }) } ``` - **Request Headers**: When fetching data inside server-side calls that require authentication, forward cookies appropriately: ```typescript const { data: user } = await useFetch('/api/auth/me', { headers: useRequestHeaders(['cookie']), }) ``` --- ## 4. State Management - Prefer simple composables with `ref` or `reactive` for shared local/global state. - Keep state local to views unless shared across layouts.