Skip to main content
Nuxt is the intuitive Vue framework that provides an amazing developer experience with powerful features like auto-imports, file-based routing, server-side rendering, and static site generation. When using Nuxt with Mizu, you’ll leverage Nuxt’s static generation mode to create a fully static site, while Mizu handles your backend API.

Why Nuxt with Mizu?

Nuxt brings the best of Vue with additional superpowers: File-based routing - Create pages by adding files to the pages/ directory. Routes are automatically generated. Auto-imports - Components, composables, and utilities are automatically imported. No more import statements! Layouts - Define reusable page layouts that wrap your pages. Composables - Vue’s Composition API with built-in composables like useFetch, useState, useRoute, and more. Server Components - Write components that run on the server (or at build time) for better performance. Developer Experience - Hot Module Replacement, TypeScript support, and excellent error messages.

Nuxt with Mizu vs Standalone Nuxt

When to use Nuxt with Mizu:
  • You want Nuxt’s DX (auto-imports, composables, file-based routing)
  • You prefer Go for backend APIs
  • You want a single binary deployment
  • You’re building an SPA or static site
When to use standalone Nuxt:
  • You need full SSR (server-side rendering at request time)
  • You want Nuxt server routes and middleware
  • You prefer Node.js for everything
  • You need Nuxt’s full-stack features (server components, API routes)

Nuxt vs Vue with Vite

How Nuxt Works with Mizu

When you build Nuxt in SPA mode for Mizu:
At runtime:
  1. Mizu serves the pre-built files
  2. Browser loads index.html + JavaScript
  3. Vue takes over and renders the app
  4. Client-side routing handles navigation
  5. API calls go to Mizu backend (Go)

Quick Start

Create a new Nuxt project with the CLI:
Visit http://localhost:3000 to see your app!

Project Structure

Configuration

Nuxt Configuration

Configure Nuxt for SPA mode and Mizu integration:

frontend/nuxt.config.ts

Configuration explained:
  • ssr: false - Runs Nuxt in SPA mode (no server-side rendering)
  • nitro.output - Outputs built files to dist/ directory
  • vite.server.hmr.clientPort - HMR through Mizu’s proxy on port 3000
  • components.dirs - Directories to auto-import components from

Backend Configuration

app/server/app.go

app/server/routes.go

File-Based Routing

Nuxt automatically generates routes based on files in the pages/ directory.

Basic Routes

Nested Routes

Dynamic Routes

Use square brackets for dynamic segments:

Route Parameters

Access route parameters with useRoute():

pages/users/[id].vue

Catch-All Routes

Create a catch-all route with [...slug].vue:

Auto-Imports

One of Nuxt’s killer features is auto-imports. No more import statements!

What Gets Auto-Imported?

Vue APIs:
Components:
Composables:
Utils:

Auto-Import Configuration

Control what gets auto-imported in nuxt.config.ts:

TypeScript Support

Nuxt automatically generates TypeScript types for auto-imports:
Your IDE will have full autocomplete and type checking!

Layouts

Layouts wrap your pages with common UI elements.

Default Layout

Create a default layout that wraps all pages:

layouts/default.vue

Custom Layouts

Create additional layouts for different page types:

layouts/auth.vue

Using Layouts in Pages

Specify which layout to use with definePageMeta:

No Layout

Disable layout for a page:

Built-in Composables

Nuxt provides powerful composables for common tasks.

useFetch

Fetch data from an API:

useAsyncData

More control over async data fetching:

useState

Shared state across components:

useRoute and useRouter

Access routing information:

useCookie

Work with cookies:

useHead

Manage document head:

Custom Composables

Create reusable composables for your app logic:

User Management Composable

Usage:

Authentication Composable

Middleware

Route middleware runs before rendering a page.

Global Middleware

Runs on every route:

Named Middleware

Runs only when specified:
Use in pages:

Multiple Middleware

Components

Auto-Imported Components

Components in components/ are automatically available:

Component Example

State Management with Pinia

For complex state, use Pinia:
Add to nuxt.config.ts:
Create a store:
Use in components:

Styling

Scoped Styles

Use scoped styles by default:

Global Styles

Create global CSS:
Import in nuxt.config.ts:

Tailwind CSS

Install Tailwind module:
Add to nuxt.config.ts:
Use in components:

CSS Modules

Plugins

Create Vue plugins:
Use in components:

Development Workflow

Starting Development

How it works:
  1. Nuxt runs dev server on port 5173
  2. Mizu runs on port 3000
  3. Requests to port 3000 proxy to Nuxt (except /api)
  4. Visit http://localhost:3000
  5. HMR works through proxy

Making Changes

Frontend changes:
  • Edit files in frontend/
  • Nuxt HMR updates browser instantly
  • Components, pages, composables auto-reload
Backend changes:
  • Edit Go files
  • Restart Mizu server
  • Or use air for auto-reload

Building for Production

Build the application:
This runs:
  1. cd frontend && npm run build - Nuxt build
  2. go build - Go binary with embedded frontend

Build Output

Running in Production

TypeScript

Nuxt has excellent TypeScript support:

Typed Composables

Typed Components

Auto-Generated Types

Nuxt generates types automatically:

Troubleshooting

HMR Not Working

Symptom: Changes don’t appear in browser Cause: HMR WebSocket not connecting through proxy Solution: Check vite.server.hmr.clientPort in nuxt.config.ts:

Hydration Mismatch

Error:
Cause: Server-rendered HTML doesn’t match client Solution: Wrap dynamic content in <ClientOnly>:

Auto-Import Not Working

Symptom: Component/composable not found Solution 1: Check file naming (must be in correct directory)
Solution 2: Restart dev server:
Solution 3: Check .nuxt/ was generated:

404 on Refresh in SPA Mode

Symptom: Page works initially, but refreshing gives 404 Cause: SPA fallback not configured Solution: Mizu automatically handles this, but ensure:

Build Fails: β€œCannot find module”

Error:
Cause: Path alias not configured Solution: Check tsconfig.json:

Real-World Example: Task Management App

Complete example showing Nuxt features:

Backend

Store

Page

Components

When to Choose Nuxt

Choose Nuxt When:

βœ… You want file-based routing with zero configuration βœ… You love Vue and want enhanced DX βœ… Auto-imports appeal to you (less boilerplate) βœ… You want built-in layouts and middleware βœ… You’re building a content-heavy site or app βœ… Your team values convention over configuration βœ… You want powerful built-in composables

Choose Vanilla Vue When:

βœ… You want complete control over setup βœ… You prefer explicit imports βœ… Bundle size is critical (Nuxt adds overhead) βœ… You’re building a library βœ… You don’t need file-based routing βœ… You prefer configuration freedom

Next Steps

Vue Guide

Compare with vanilla Vue + Vite

Next.js Guide

React equivalent of Nuxt

Pinia

Official Vue state management

Nuxt Docs

Official Nuxt documentation