组件
- 手风琴 (Accordion)
- 警告 (Alert)
- 警告对话框 (Alert Dialog)
- 宽高比 (Aspect Ratio)
- 头像 (Avatar)
- 徽章 (Badge)
- 面包屑 (Breadcrumb)
- 按钮 (Button)
- 按钮组 (Button Group)
- 日历 (Calendar)
- 卡片 (Card)
- 轮播图 (Carousel)
- 图表 (Chart)
- 复选框 (Checkbox)
- 折叠面板 (Collapsible)
- 组合框 (Combobox)
- 命令面板 (Command)
- 上下文菜单 (Context Menu)
- 数据表格 (Data Table)
- 日期选择器 (Date Picker)
- 对话框 (Dialog)
- 抽屉 (Drawer)
- 下拉菜单 (Dropdown Menu)
- 空状态 (Empty)
- 字段 (Field)
- 表单 (Form)
- 悬停卡片 (Hover Card)
- 输入框 (Input)
- 输入组 (Input Group)
- 验证码输入 (Input OTP)
- 项 (Item)
- 键盘按键 (Kbd)
- 标签 (Label)
- 菜单栏 (Menubar)
- 原生选择器 (Native Select)
- 导航菜单 (Navigation Menu)
- 数字输入框 (Number Field)
- 分页 (Pagination)
- 引脚输入 (Pin Input)
- 气泡卡片 (Popover)
- 进度条 (Progress)
- 单选框组 (Radio Group)
- 范围日历 (Range Calendar)
- 可调整大小 (Resizable)
- 滚动区域 (Scroll Area)
- 选择器 (Select)
- 分隔线 (Separator)
- 侧边栏抽屉 (Sheet)
- 侧边栏 (Sidebar)
- 骨架屏 (Skeleton)
- 滑块 (Slider)
- 轻量提示 (Sonner)
- 加载动画 (Spinner)
- 步骤条 (Stepper)
- 开关 (Switch)
- 表格 (Table)
- 标签页 (Tabs)
- 标签输入 (Tags Input)
- 文本域 (Textarea)
- 吐司提示 (Toast)
- 切换按钮 (Toggle)
- 切换按钮组 (Toggle Group)
- 工具提示 (Tooltip)
- 排版 (Typography)
开始使用
创建项目
首先使用 create-nuxt-app 创建一个新的 Nuxt 项目
pnpm create nuxt@latest
如果你遇到 ERROR: Cannot read properties of undefined (reading 'sys') (x4) 错误,请根据此 issue 的建议,将 TypeScript 安装为依赖项。
pnpm add -D typescript
添加 Tailwind CSS
如何设置 tailwindcss
pnpm add tailwindcss @tailwindcss/vite -D
将 app/assets/css/tailwind.css 中的所有内容替换为以下代码
@import "tailwindcss";使用以下代码更新 nuxt.config.ts
import tailwindcss from '@tailwindcss/vite'
export default defineNuxtConfig({
// ...
css: ['~/assets/css/tailwind.css'],
vite: {
plugins: [
tailwindcss(),
],
},
})添加 Nuxt 模块
跳过此步骤会因为 Nuxt 的自动导入功能而触发大量控制台警告。
安装以下软件包。
pnpm dlx nuxi@latest module add shadcn-nuxt
配置 nuxt.config.ts
export default defineNuxtConfig({
// ...
modules: ['shadcn-nuxt'],
shadcn: {
/**
* Prefix for all the imported component.
* @default "Ui"
*/
prefix: '',
/**
* Directory that the component lives in.
* Will respect the Nuxt aliases.
* @link https://nuxtjs.org.cn/docs/api/nuxt-config#alias
* @default "@/components/ui"
*/
componentDir: '@/components/ui'
}
})添加一个用于提供 ssrWidth 的 Nuxt 插件(可选)
某些组件需要通过 VueUse 设置 ssrWidth,以避免在移动端出现水合(Hydration)错误。
将以下插件添加到你的 Nuxt 应用中:app/plugins/ssr-width.ts
阅读更多关于 useSSRWidth 的信息
import { provideSSRWidth } from '@vueuse/core'
export default defineNuxtPlugin((nuxtApp) => {
provideSSRWidth(1024, nuxtApp.vueApp)
})运行 Nuxt Prepare
如果你正在初始化一个新项目,你需要运行该命令以便 Nuxt 生成必要的 .nuxt 文件夹
pnpm dlx nuxi prepare
运行 CLI
运行 shadcn-vue 初始化命令来配置你的项目
pnpm dlx shadcn-vue@latest init
系统会询问你几个问题以配置 components.json。
Which color would you like to use as base color? › Neutral添加组件
现在你可以开始将组件添加到你的项目中了。
pnpm dlx shadcn-vue@latest add button
上面的命令会将 Button 组件添加到你的项目中。Nuxt 的自动导入(autoImport)功能将处理组件的导入,你可以直接使用它
<template>
<div>
<Button>Click me</Button>
</div>
</template>