โ† Back
ๅ‰็ซฏๅผ€ๅ‘ 2025.04.06 ยท 2 min read

Nuxt3: Beginner's Guide and Principles Introduction [Learning Notes]

ๅ‰็ซฏๅผ€ๅ‘

Table of Contents

Nuxt 3 Getting Started and Principles Introduction

๐Ÿ’ก What is Nuxt 3?

Nuxt 3 is a full-stack frontend framework built on Vue 3 and Vite, supporting:

  • Server-Side Rendering (SSR)
  • Static Site Generation (SSG)
  • Single-Page Applications (SPA)
  • Building full-stack applications (with API support)

Nuxt 3 is an โ€œenhanced versionโ€ of Vue, helping you simplify project structure and development workflow.


๐Ÿ”ง Core Principles

FeatureHow Nuxt Handles It
โœ… Page RoutingAutomatically generated based on the pages/ directory structure
โœ… Auto Component ImportAutomatically registers components in components/
โœ… SSR / SSG / SPABuilt-in support, switch via commands or configuration
โœ… API EndpointsSupports writing backend logic in server/api/
โœ… State ManagementRecommended to use pinia (Vueโ€™s official state management library)
โœ… Build PerformanceDefaults to Vite (fast build) or can switch to Webpack
โœ… TypeScriptNative support

๐Ÿš€ Quick Start

1. Create Project

npx nuxi init my-nuxt-app
cd my-nuxt-app
npm install
npm run dev

2. Directory Structure

my-nuxt-app/
โ”œโ”€โ”€ pages/             # Page directory (automatically becomes routes)
โ”œโ”€โ”€ components/        # Component directory (auto-imported)
โ”œโ”€โ”€ layouts/           # Layout pages
โ”œโ”€โ”€ app.vue            # Global entry file
โ”œโ”€โ”€ nuxt.config.ts     # Configuration file
โ”œโ”€โ”€ server/api/        # Backend API directory (for full-stack development)

โœ๏ธ Example Code

Page: pages/index.vue

<template>
  <h1>Welcome to Nuxt 3</h1>
</template>

Visit http://localhost:3000 to see the effect.


API Endpoint: server/api/hello.ts

export default defineEventHandler(() => {
  return { message: 'Hello Nuxt API' }
})

API access address: http://localhost:3000/api/hello

Return result:

{ "message": "Hello Nuxt API" }

Client-side API Call

const { data } = await useFetch('/api/hello')

โœ… Who is Nuxt 3 For?

  • Developers who use Vue but donโ€™t want to manually configure build, routing, and SSR
  • Those who want to build high-performance, SEO-friendly websites/applications
  • Developers who want to use one codebase for frontend + backend APIs

  • Chinese Official Website: https://nuxt.com.cn
  • Official Documentation: https://nuxt.com
  • Video Courses: Search for โ€œNuxt3 ๅ…ฅ้—จโ€ (Nuxt3 Getting Started) on Bilibili