nuxt-ui-2
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseNuxt UI
Nuxt UI
Vue component library built on Reka UI + Tailwind CSS + Tailwind Variants. Works with Nuxt, Vue (Vite), Laravel (Inertia), and AdonisJS (Inertia).
基于Reka UI + Tailwind CSS + Tailwind Variants构建的Vue组件库。可在Nuxt、Vue(Vite)、Laravel(Inertia)和AdonisJS(Inertia)环境中使用。
Installation
安装
Nuxt
Nuxt
bash
pnpm add @nuxt/ui tailwindcssts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
css: ['~/assets/css/main.css']
})css
/* app/assets/css/main.css */
@import "tailwindcss";
@import "@nuxt/ui";vue
<!-- app.vue -->
<template>
<UApp>
<NuxtPage />
</UApp>
</template>bash
pnpm add @nuxt/ui tailwindcssts
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
css: ['~/assets/css/main.css']
})css
/* app/assets/css/main.css */
@import "tailwindcss";
@import "@nuxt/ui";vue
<!-- app.vue -->
<template>
<UApp>
<NuxtPage />
</UApp>
</template>Vue (Vite)
Vue(Vite)
bash
pnpm add @nuxt/ui tailwindcssts
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui()
]
})ts
// src/main.ts
import './assets/main.css'
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import ui from '@nuxt/ui/vue-plugin'
import App from './App.vue'
const app = createApp(App)
const router = createRouter({
routes: [],
history: createWebHistory()
})
app.use(router)
app.use(ui)
app.mount('#app')css
/* assets/main.css */
@import "tailwindcss";
@import "@nuxt/ui";vue
<!-- src/App.vue -->
<template>
<UApp>
<RouterView />
</UApp>
</template>Vue: Addto your rootclass="isolate"in<div id="app">.index.html
Vue + Inertia: Useinui({ router: 'inertia' }).vite.config.ts
bash
pnpm add @nuxt/ui tailwindcssts
// vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui()
]
})ts
// src/main.ts
import './assets/main.css'
import { createApp } from 'vue'
import { createRouter, createWebHistory } from 'vue-router'
import ui from '@nuxt/ui/vue-plugin'
import App from './App.vue'
const app = createApp(App)
const router = createRouter({
routes: [],
history: createWebHistory()
})
app.use(router)
app.use(ui)
app.mount('#app')css
/* assets/main.css */
@import "tailwindcss";
@import "@nuxt/ui";vue
<!-- src/App.vue -->
<template>
<UApp>
<RouterView />
</UApp>
</template>Vue提示:在的根元素index.html上添加<div id="app">。class="isolate"
Vue + Inertia提示:在中使用vite.config.ts。ui({ router: 'inertia' })
UApp
UApp
Wrapping your app in is required — it provides global config for toasts, tooltips, and programmatic overlays. It also accepts a prop for i18n (see composables reference).
UApplocale必须将应用包裹在中——它为提示框、工具提示和程序化浮层提供全局配置,还支持通过属性实现国际化(详见组合式函数参考文档)。
UApplocaleIcons
图标
Nuxt UI uses Iconify for 200,000+ icons. In Nuxt, is auto-registered. In Vue, icons work out of the box via the Vite plugin.
@nuxt/iconNuxt UI使用Iconify提供的20万+图标。在Nuxt中,会自动注册;在Vue中,通过Vite插件即可直接使用图标。
@nuxt/iconNaming convention
命名规则
Icons use the format :
i-{collection}-{name}vue
<UIcon name="i-lucide-sun" class="size-5" />
<UButton icon="i-lucide-plus" label="Add" />
<UAlert icon="i-lucide-info" title="Heads up" />Browse all icons at icones.js.org. Thecollection is used throughout Nuxt UI defaults.lucide
图标采用的格式:
i-{图标集}-{图标名}vue
<UIcon name="i-lucide-sun" class="size-5" />
<UButton icon="i-lucide-plus" label="Add" />
<UAlert icon="i-lucide-info" title="Heads up" />可在icones.js.org浏览所有图标。Nuxt UI默认使用图标集。lucide
Install icon collections locally
本地安装图标集
bash
pnpm i @iconify-json/lucide
pnpm i @iconify-json/simple-iconsbash
pnpm i @iconify-json/lucide
pnpm i @iconify-json/simple-iconsCustom local collections (Nuxt)
自定义本地图标集(Nuxt)
ts
// nuxt.config.ts
export default defineNuxtConfig({
icon: {
customCollections: [{
prefix: 'custom',
dir: './app/assets/icons'
}]
}
})vue
<UIcon name="i-custom-my-icon" />ts
// nuxt.config.ts
export default defineNuxtConfig({
icon: {
customCollections: [{
prefix: 'custom',
dir: './app/assets/icons'
}]
}
})vue
<UIcon name="i-custom-my-icon" />Theming & Branding
主题与品牌定制
Nuxt UI ships with a default look. The goal is to adapt it to your brand so every app looks unique.
Always use semantic utilities (, , ), never raw Tailwind palette colors. See references/theming.md for the full list.
text-defaultbg-elevatedborder-mutedNuxt UI自带默认样式,目标是让你可以根据品牌需求定制,让每个应用都具备独特外观。
请始终使用语义化工具类(、、),不要直接使用Tailwind的原始调色板颜色。完整列表详见主题定制参考文档。
text-defaultbg-elevatedborder-mutedColors
颜色
7 semantic colors (, , , , , , ) configurable at runtime:
primarysecondarysuccessinfowarningerrorneutralts
// Nuxt — app.config.ts
export default defineAppConfig({
ui: { colors: { primary: 'indigo', neutral: 'zinc' } }
})ts
// Vue — vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: { colors: { primary: 'indigo', neutral: 'zinc' } }
})
]
})提供7种语义化颜色(、、、、、、),可在运行时配置:
primarysecondarysuccessinfowarningerrorneutralts
// Nuxt — app.config.ts
export default defineAppConfig({
ui: { colors: { primary: 'indigo', neutral: 'zinc' } }
})ts
// Vue — vite.config.ts
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: { colors: { primary: 'indigo', neutral: 'zinc' } }
})
]
})Customizing components
组件定制
Override priority (highest wins): prop / prop > global config > theme defaults.
uiclassThe prop overrides a component's slots after variants are computed — it wins over everything:
uivue
<UButton :ui="{ base: 'rounded-none', trailingIcon: 'size-3 rotate-90' }" />
<UCard :ui="{ header: 'bg-muted', body: 'p-8' }" />Read the generated theme file to find slot names for any component:
- Nuxt:
.nuxt/ui/<component>.ts - Vue:
node_modules/.nuxt-ui/ui/<component>.ts
For CSS variables, custom colors, global config, compound variants, and a full brand customization playbook, see references/theming.md
优先级顺序(从高到低):属性 / 属性 > 全局配置 > 主题默认值。
uiclassuivue
<UButton :ui="{ base: 'rounded-none', trailingIcon: 'size-3 rotate-90' }" />
<UCard :ui="{ header: 'bg-muted', body: 'p-8' }" />查看生成的主题文件可获取任意组件的插槽名称:
- Nuxt:
.nuxt/ui/<component>.ts - Vue:
node_modules/.nuxt-ui/ui/<component>.ts
关于CSS变量、自定义颜色、全局配置、复合变量以及完整的品牌定制指南,请查看主题定制参考文档
Composables
组合式函数
ts
// Notifications
const toast = useToast()
toast.add({ title: 'Saved', color: 'success', icon: 'i-lucide-check' })
// Programmatic overlays
const overlay = useOverlay()
const modal = overlay.create(MyModal)
const { result } = modal.open({ title: 'Confirm' })
await result
// Keyboard shortcuts
defineShortcuts({
meta_k: () => openSearch(),
escape: () => close()
})For full composable reference, see references/composables.md
ts
// 通知提示
const toast = useToast()
toast.add({ title: 'Saved', color: 'success', icon: 'i-lucide-check' })
// 程序化浮层
const overlay = useOverlay()
const modal = overlay.create(MyModal)
const { result } = modal.open({ title: 'Confirm' })
await result
// 键盘快捷键
defineShortcuts({
meta_k: () => openSearch(),
escape: () => close()
})完整的组合式函数参考请查看组合式函数参考文档
Form validation
表单验证
Uses Standard Schema — works with Zod, Valibot, Yup, or Joi.
vue
<script setup lang="ts">
import { z } from 'zod'
const schema = z.object({
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Min 8 characters')
})
type Schema = z.output<typeof schema>
const state = reactive<Partial<Schema>>({ email: '', password: '' })
function onSubmit() {
// UForm validates before emitting @submit — state is valid here
}
</script>
<template>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormField name="email" label="Email" required>
<UInput v-model="state.email" type="email" />
</UFormField>
<UFormField name="password" label="Password" required>
<UInput v-model="state.password" type="password" />
</UFormField>
<UButton type="submit">Sign in</UButton>
</UForm>
</template>For all form components and validation patterns, see references/components.md
基于标准Schema实现,支持Zod、Valibot、Yup或Joi。
vue
<script setup lang="ts">
import { z } from 'zod'
const schema = z.object({
email: z.string().email('Invalid email'),
password: z.string().min(8, 'Min 8 characters')
})
type Schema = z.output<typeof schema>
const state = reactive<Partial<Schema>>({ email: '', password: '' })
function onSubmit() {
// UForm会在触发@submit前验证——此时state已确保合法
}
</script>
<template>
<UForm :schema="schema" :state="state" @submit="onSubmit">
<UFormField name="email" label="Email" required>
<UInput v-model="state.email" type="email" />
</UFormField>
<UFormField name="password" label="Password" required>
<UInput v-model="state.password" type="password" />
</UFormField>
<UButton type="submit">Sign in</UButton>
</UForm>
</template>所有表单组件和验证模式请查看组件参考文档
Overlays
浮层组件
vue
<!-- Modal -->
<UModal v-model:open="isOpen" title="Edit" description="Edit your profile">
<template #body>Content</template>
<template #footer>
<UButton variant="ghost" @click="isOpen = false">Cancel</UButton>
<UButton @click="save">Save</UButton>
</template>
</UModal>
<!-- Slideover (side panel) -->
<USlideover v-model:open="isOpen" title="Settings" side="right">
<template #body>Content</template>
</USlideover>
<!-- Dropdown menu (flat array) -->
<UDropdownMenu :items="[
{ label: 'Edit', icon: 'i-lucide-pencil' },
{ type: 'separator' },
{ label: 'Delete', icon: 'i-lucide-trash', color: 'error' }
]">
<UButton icon="i-lucide-ellipsis-vertical" variant="ghost" />
</UDropdownMenu>
<!-- Dropdown menu (nested array — groups with automatic separators) -->
<UDropdownMenu :items="[
[{ label: 'Edit', icon: 'i-lucide-pencil' }, { label: 'Duplicate', icon: 'i-lucide-copy' }],
[{ label: 'Delete', icon: 'i-lucide-trash', color: 'error' }]
]">
<UButton icon="i-lucide-ellipsis-vertical" variant="ghost" />
</UDropdownMenu>For all overlay components, see references/components.md
vue
<!-- 模态框 -->
<UModal v-model:open="isOpen" title="Edit" description="Edit your profile">
<template #body>Content</template>
<template #footer>
<UButton variant="ghost" @click="isOpen = false">Cancel</UButton>
<UButton @click="save">Save</UButton>
</template>
</UModal>
<!-- 侧边滑出面板 -->
<USlideover v-model:open="isOpen" title="Settings" side="right">
<template #body>Content</template>
</USlideover>
<!-- 下拉菜单(扁平数组) -->
<UDropdownMenu :items="[
{ label: 'Edit', icon: 'i-lucide-pencil' },
{ type: 'separator' },
{ label: 'Delete', icon: 'i-lucide-trash', color: 'error' }
]">
<UButton icon="i-lucide-ellipsis-vertical" variant="ghost" />
</UDropdownMenu>
<!-- 下拉菜单(嵌套数组——自动分组并添加分隔线) -->
<UDropdownMenu :items="[
[{ label: 'Edit', icon: 'i-lucide-pencil' }, { label: 'Duplicate', icon: 'i-lucide-copy' }],
[{ label: 'Delete', icon: 'i-lucide-trash', color: 'error' }]
]">
<UButton icon="i-lucide-ellipsis-vertical" variant="ghost" />
</UDropdownMenu>所有浮层组件请查看组件参考文档
Layouts
布局组件
Nuxt UI provides components to compose full page layouts. Load the reference matching your use case:
| Layout | Description | Reference |
|---|---|---|
| Page | Landing, blog, changelog, pricing — public-facing pages | layouts/page.md |
| Dashboard | Admin UI with resizable sidebar and panels | layouts/dashboard.md |
| Docs | Documentation with sidebar nav and TOC | layouts/docs.md |
| Chat | AI chat with messages and prompt | layouts/chat.md |
| Editor | Rich text editor with toolbars | layouts/editor.md |
Nuxt UI提供用于组合整页布局的组件。请根据你的使用场景查看对应参考文档:
| 布局类型 | 描述 | 参考文档 |
|---|---|---|
| 页面布局 | 适用于着陆页、博客、更新日志、定价页等面向公众的页面 | layouts/page.md |
| 仪表板布局 | 带可调整大小侧边栏和面板的管理后台UI | layouts/dashboard.md |
| 文档布局 | 带侧边导航和目录的文档页面 | layouts/docs.md |
| 聊天布局 | AI聊天界面,包含消息列表和输入框 | layouts/chat.md |
| 编辑器布局 | 带工具栏的富文本编辑器 | layouts/editor.md |
Templates
模板
Official starter templates at github.com/nuxt-ui-templates:
| Template | Framework | GitHub |
|---|---|---|
| Starter | Nuxt | nuxt-ui-templates/starter |
| Starter | Vue | nuxt-ui-templates/starter-vue |
| Dashboard | Nuxt | nuxt-ui-templates/dashboard |
| Dashboard | Vue | nuxt-ui-templates/dashboard-vue |
| SaaS | Nuxt | nuxt-ui-templates/saas |
| Landing | Nuxt | nuxt-ui-templates/landing |
| Docs | Nuxt | nuxt-ui-templates/docs |
| Portfolio | Nuxt | nuxt-ui-templates/portfolio |
| Chat | Nuxt | nuxt-ui-templates/chat |
| Editor | Nuxt | nuxt-ui-templates/editor |
| Changelog | Nuxt | nuxt-ui-templates/changelog |
| Starter | Laravel | nuxt-ui-templates/starter-laravel |
| Starter | AdonisJS | nuxt-ui-templates/starter-adonis |
When starting a new project, clone the matching template instead of setting up from scratch.
官方启动模板托管在github.com/nuxt-ui-templates:
| 模板类型 | 框架 | GitHub地址 |
|---|---|---|
| 基础模板 | Nuxt | nuxt-ui-templates/starter |
| 基础模板 | Vue | nuxt-ui-templates/starter-vue |
| 仪表板模板 | Nuxt | nuxt-ui-templates/dashboard |
| 仪表板模板 | Vue | nuxt-ui-templates/dashboard-vue |
| SaaS模板 | Nuxt | nuxt-ui-templates/saas |
| 着陆页模板 | Nuxt | nuxt-ui-templates/landing |
| 文档模板 | Nuxt | nuxt-ui-templates/docs |
| 作品集模板 | Nuxt | nuxt-ui-templates/portfolio |
| 聊天模板 | Nuxt | nuxt-ui-templates/chat |
| 编辑器模板 | Nuxt | nuxt-ui-templates/editor |
| 更新日志模板 | Nuxt | nuxt-ui-templates/changelog |
| 基础模板 | Laravel | nuxt-ui-templates/starter-laravel |
| 基础模板 | AdonisJS | nuxt-ui-templates/starter-adonis |
启动新项目时,建议直接克隆匹配的模板,而非从零开始搭建。
Additional references
额外参考文档
Load based on your task — do not load all at once:
- references/theming.md — CSS variables, custom colors, component theme overrides
- references/components.md — all 125+ components by category with props and usage
- references/composables.md — useToast, useOverlay, defineShortcuts
- Generated theme files — all slots, variants, and default classes for any component (Nuxt: , Vue:
.nuxt/ui/<component>.ts)node_modules/.nuxt-ui/ui/<component>.ts
请根据你的任务需求查看对应文档——不要一次性加载所有文档:
- references/theming.md — CSS变量、自定义颜色、组件主题覆盖
- references/components.md — 按分类整理的125+个组件,含属性和使用示例
- references/composables.md — useToast、useOverlay、defineShortcuts等组合式函数
- 生成的主题文件 — 任意组件的所有插槽、变量和默认类(Nuxt:,Vue:
.nuxt/ui/<component>.ts)node_modules/.nuxt-ui/ui/<component>.ts