# macroui-vue **Repository Path**: macroui/macroui-vue ## Basic Information - **Project Name**: macroui-vue - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-06-03 - **Last Updated**: 2026-07-02 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # @macroui/macroui-vue
`
### 5.5 扩展新语言
```ts
// src/locales/ja.ts
export default {
name: 'ja',
el: {
button: {
confirm: '確認',
cancel: 'キャンセル',
},
pagination: {
total: '合計 {total} 件',
},
},
}
```
```ts
// 注入到全局
import ja from '@/locales/ja'
app.use(ElConfigProvider, {
locale: ja,
})
```
### 5.6 ⚠️ 重要规则
> **邮箱地址不要写入语言包**,应写死在页面组件中。
```vue
✅ 正确:写死在组件中
联系我们: support@example.com
❌ 错误:写入语言包
export default {
contact: 'support@example.com',
}
```
---
## 6. 全局配置 ElConfigProvider
`ElConfigProvider` 用于全局配置组件默认值。
```vue
```
### 6.1 ElConfigProvider Props
| Prop | 类型 | 默认 | 说明 |
|------|------|------|------|
| `locale` | `Language` | `zhCn` | 当前语言 |
| `size` | `SizeType` | `'default'` | 全局尺寸 |
| `buttonType` | `ButtonType` | - | 全局按钮类型 |
| `messageOptions` | `MessageOptions` | - | Message 全局配置 |
| `zIndex` | `number` | `2000` | 弹窗 z-index 起始值 |
| `namespace` | `string` | `'el'` | 组件 CSS 类前缀 |
### 6.2 SizeType
`'large' | 'default' | 'small' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'`
> 注:扩展尺寸(`xs` / `sm` / `md` / `lg` / `xl`)仅 macroui-vue 支持,Element Plus 仅有前三档。
---
## 7. 组件完整参考
### 7.1 基础组件
#### ElButton — 按钮
```vue
默认按钮
主要按钮
成功按钮
警告按钮
危险按钮
信息按钮
朴素按钮
圆角
圆
搜索
加载中
大
默认
小
超小
上一页
下一页
```
**Props 关键字段**:`type`(`'primary' | 'success' | 'warning' | 'danger' | 'info' | 'default'`)、`size`、`plain`、`round`、`circle`、`loading`、`disabled`、`icon`、`native-type`、`autofocus`、`tag`、`text` / `bg` / `link`。
**Events**:`click`、`mousedown`。
**Slots**:`default`、`loading`、`icon`。
#### ElLink — 文字链接
```vue
默认
主要
无下划线
禁用
```
#### ElText — 文本
```vue
默认
主要
危险
大号
省略...
```
#### ElIcon — 图标
```vue
```
#### ElSpace — 间距
```vue
1
2
1
2
按钮{{ i }}
```
#### ElDivider — 分割线
```vue
文字
垂直
```
#### ElScrollbar — 滚动条
```vue
{{ i }}
```
### 7.2 表单组件
#### ElInput — 输入框
```vue
https://
.com
```
**Props**:`modelValue`、`type`、`placeholder`、`disabled`、`clearable`、`show-password`、`prefix-icon`、`suffix-icon`、`maxlength`、`minlength`、`show-word-limit`、`autocomplete`、`name`、`size`、`input-style`。
**Events**:`update:modelValue`、`input`、`change`、`focus`、`blur`、`clear`、`keydown`、`keyup`。
**Slots**:`prefix`、`suffix`、`prepend`、`append`。
#### ElInputNumber — 数字输入
```vue
```
#### ElInputTag — 标签输入
```vue
```
#### ElInputOtp — 一次性密码
```vue
```
#### ElSelect — 选择器
```vue
```
**Props**:`modelValue`、`multiple`、`disabled`、`size`、`clearable`、`filterable`、`remote`、`loading-text`、`no-match-text`、`no-data-text`、`placeholder`、`collapse-tags`、`multiple-limit`、`value-key`。
#### ElOption / ElOptionGroup
**ElOption Props**:`value`、`label`、`disabled`。
**ElOptionGroup Props**:`label`、`disabled`。
#### ElCascader — 级联选择
```vue
```
**Props**:`modelValue`、`options`、`props`、`size`、`placeholder`、`disabled`、`clearable`、`filterable`、`show-all-levels`、`collapse-tags`、`separator`、`before-filter`、`max-collapse-tags`。
#### ElTreeSelect — 树形选择
```vue
```
#### ElTree — 树形控件
```vue
```
#### ElTreeV2 — 虚拟树
```vue
```
#### ElCheckbox — 多选框
```vue
选项
A
B
```
#### ElCheckboxGroup / ElCheckboxButton
```vue
A
B
```
#### ElRadio — 单选
```vue
男
男
女
男
女
```
#### ElSwitch — 开关
```vue
```
#### ElSlider — 滑块
```vue
```
#### ElRate — 评分
```vue
```
#### ElColorPicker — 颜色选择器
```vue
```
#### ElDatePicker — 日期选择器
```vue
```
#### ElTimePicker — 时间选择器
```vue
```
#### ElTimeSelect — 时间段选择
```vue
```
#### ElUpload — 上传
```vue
点击上传
将文件拖到此处,或点击上传
```
#### ElForm — 表单
```vue
提交
重置
```
**Form Methods(ref)**:`validate(cb?)`、`validateField(props, cb?)`、`resetFields()`、`clearValidate(props?)`、`scrollToField(prop)`。
**ElFormItem Props**:`prop`、`label`、`label-width`、`required`、`rules`、`error`、`show-message`、`inline-message`、`size`。
#### ElMention — @提及
```vue
```
#### ElAutocomplete — 自动补全
```vue
```
### 7.3 数据展示
#### ElTable — 表格
```vue
编辑
```
**关键 Props**:`data`、`height`、`max-height`、`stripe`、`border`、`size`、`fit`、`show-header`、`highlight-current-row`、`row-class-name`、`row-style`、`cell-class-name`、`cell-style`、`empty-text`、`show-summary`、`summary-method`、`span-method`、`lazy`、`load`、`tree-props`、`default-expand-all`、`default-sort`。
**关键 Events**:`select`、`select-all`、`selection-change`、`cell-click`、`row-click`、`row-dblclick`、`sort-change`、`current-change`、`expand-change`、`filter-change`。
#### ElTableColumn — 表格列
**关键 Props**:`type`(`selection` / `index` / `expand`)、`prop`、`label`、`width`、`min-width`、`fixed`、`sortable`、`sort-orders`、`sort-method`、`sort-by`、`resizable`、`formatter`、`show-overflow-tooltip`、`align`、`header-align`、`class-name`、`label-class-name`、`selectable`、`reserve-selection`、`filters`、`filter-placement`、`filter-multiple`、`filter-method`、`filtered-value`、`render-header`。
#### ElTableV2 — 虚拟表格
```vue
```
#### ElPagination — 分页
```vue
```
#### ElTag — 标签
```vue
标签1
成功
警告
危险
大号
圆角
可选中
```
#### ElBadge — 徽章
```vue
按钮
≤9
红点
```
#### ElAvatar — 头像
```vue
USER
```
#### ElSkeleton — 骨架屏
```vue
真实内容
```
#### ElProgress — 进度条
```vue
```
#### ElEmpty — 空状态
```vue
重新加载
```
#### ElResult — 结果页
```vue
返回
```
#### ElDescriptions — 描述列表
```vue
张三
zhang@example.com
13800138000
北京市朝阳区
```
#### ElStatistic — 统计数值
```vue
元
```
#### ElTimeline — 时间轴
```vue
创建项目
里程碑 1
```
#### ElCalendar — 日历
```vue
{{ data.day.split('-').slice(1).join('-') }}
```
#### ElImage — 图片
```vue
```
#### ElCarousel — 走马灯
```vue
{{ item }}
```
#### ElCollapse — 折叠面板
```vue
内容1
内容2
```
#### ElTransfer — 穿梭框
```vue
```
#### ElWatermark — 水印
```vue
有水印内容
```
### 7.4 反馈组件
#### ElAlert — 警告提示
```vue
```
#### ElDialog — 对话框
```vue
内容
取消
确认
```
**关键 Props**:`modelValue`、`title`、`width`、`fullscreen`、`top`、`modal`、`append-to-body`、`lock-scroll`、`close-on-click-modal`、`close-on-press-escape`、`show-close`、`before-close`、`draggable`、`overflow`、`center`、`align-center`、`destroy-on-close`、`transition`。
#### ElDrawer — 抽屉
```vue
内容
```
**关键 Props**:`modelValue`、`direction`、`size`、`title`、`modal`、`drawer-class`、`wrapper-closable`、`close-on-press-escape`、`destroy-on-close`、`with-header`、`show-close`、`z-index`、`append-to-body`、`lock-scroll`。
#### ElMessage — 消息提示(函数式)
```ts
import { ElMessage } from '@macroui/macroui-vue'
ElMessage.success('操作成功')
ElMessage.warning('警告信息')
ElMessage.error('错误信息')
ElMessage.info('提示信息')
ElMessage({
message: '带图标',
type: 'success',
duration: 3000,
showClose: true,
dangerouslyUseHTMLString: true,
customClass: 'my-message',
onClose: () => console.log('closed'),
})
```
**MessageOptions**:`message`、`type`、`icon`、`dangerouslyUseHTMLString`、`customClass`、`duration`、`showClose`、`center`、`onClose`、`offset`、`appendTo`、`grouping`。
#### ElMessageBox — 消息弹框
```ts
import { ElMessageBox } from '@macroui/macroui-vue'
await ElMessageBox.alert('内容', '标题', { type: 'warning' })
try {
await ElMessageBox.confirm('确定删除?', '提示', { type: 'warning' })
} catch {
// 取消
}
const { value } = await ElMessageBox.prompt('请输入名字', '提示', {
inputPattern: /^.{2,20}$/,
inputErrorMessage: '长度 2-20',
})
```
#### ElNotification — 通知
```ts
import { ElNotification } from '@macroui/macroui-vue'
ElNotification({
title: '标题',
message: '内容',
type: 'success',
position: 'top-right',
duration: 4500,
})
```
**位置 options**:`top-right` / `top-left` / `bottom-right` / `bottom-left`。
#### ElPopconfirm — 弹出确认
```vue
删除
```
#### ElTooltip — 文字提示
```vue
悬停
多行内容
亮色
```
**关键 Props**:`content`、`placement`、`disabled`、`offset`、`transition`、`show-after`、`hide-after`、`controlled`、`visible`、`trigger`(`hover` / `click` / `focus` / `contextmenu`)、`teleported`。
#### ElPopover — 弹出框
```vue
弹出内容
点击触发
```
#### ElLoading — 加载状态
```vue
内容
全屏 loading
```
**Options**:`target`、`fullscreen`、`lock`、`text`、`spinner`、`background`、`customClass`。
#### ElTour — 漫游式引导
```vue
```
### 7.5 导航组件
#### ElMenu — 导航菜单
```vue
首页
产品
产品A
产品B
关于
...
```
**关键 Props**:`mode`(`horizontal` / `vertical`)、`default-active`、`collapse`、`default-openeds`、`unique-opened`、`menu-trigger`、`router`、`collapse-transition`、`arrow-icon`、`ellipsis-icon`。
#### ElMenuItem / ElSubMenu / ElMenuItemGroup
```vue
编辑
子菜单
选项1
```
#### ElTabs — 标签页
```vue
内容1
内容2
内容3
...
...
```
**关键 Props**:`v-model`、`type`(`card` / `border-card`)、`tab-position`、`closable`、`addable`、`editable`、`before-leave`。
#### ElTabPane — 标签页内容
**关键 Props**:`name`、`label`、`disabled`、`lazy`、`closable`、`contextmenu`。
#### ElBreadcrumb — 面包屑
```vue
首页
列表
详情
```
#### ElDropdown — 下拉菜单
```vue
下拉菜单
选项1
选项2(禁用)
选项3
操作
...
```
#### ElSteps — 步骤条
```vue
...
```
**关键 Props**:`space`、`direction`、`active`、`align-center`、`simple`、`finish-status`、`process-status`。
**ElStep Props**:`title`、`description`、`icon`、`status`。
#### ElPageHeader — 页头
```vue
```
#### ElAffix — 固钉
```vue
固定按钮
```
#### ElBacktop — 回到顶部
```vue
```
#### ElAnchor — 锚点
```vue
```
### 7.6 布局组件
#### ElContainer / ElHeader / ElAside / ElMain / ElFooter
```vue
Header
Aside
Main
Footer
```
#### ElRow / ElCol — 栅格
```vue
8/24
8/24
8/24
...
响应式
flex
```
**ElRow**:`gutter`、`type`、`justify`、`align`、`tag`。
**ElCol**:`span`、`offset`、`push`、`pull`、`xs`、`sm`、`md`、`lg`、`xl`、`tag`。
#### ElSplitter — 分隔面板
```vue
左
右
```
#### ElSegmented — 分段控制器
```vue
```
#### ElBorder — 边框
```vue
带边框容器
自定义边框
```
#### ElInfiniteScroll — 无限滚动指令
```vue
- {{ item.name }}
```
---
## 8. 工具函数与 Hooks
### 8.1 入口导出
```ts
import * as MacrouiVue from '@macroui/macroui-vue'
import {
ElMessage,
ElMessageBox,
ElNotification,
ElLoading,
} from '@macroui/macroui-vue'
```
### 8.2 useLocale
```ts
import { useLocale } from '@macroui/macroui-vue'
const { t, locale } = useLocale()
t('el.pagination.total', { total: 100 })
```
### 8.3 useZIndex
```ts
import { useZIndex } from '@macroui/macroui-vue'
const { initialZIndex, currentZIndex, nextZIndex } = useZIndex()
nextZIndex() // 取得下一个 z-index
```
### 8.4 useNamespace
```ts
import { useNamespace } from '@macroui/macroui-vue'
const ns = useNamespace('button')
ns.b() // 'el-button'
ns.is('disabled') // 'is-disabled'
ns.m('primary') // 'el-button--primary'
```
### 8.5 类型导出
```ts
import type {
ButtonType,
ButtonSize,
SizeType,
FormInstance,
FormRules,
FormItemRule,
MenuItemRegistered,
TableInstance,
TreeInstance,
UploadFile,
UploadFiles,
UploadUserFile,
TreeNodeData,
CascaderOption,
CascaderValue,
SelectOption,
SelectOptionGroup,
MessageOptions,
MessageType,
NotificationOptions,
DateCell,
CalendarInstance,
} from '@macroui/macroui-vue'
```
### 8.6 工具函数
| 函数 | 用途 |
|------|------|
| `useLocale()` | 获取当前 locale |
| `useZIndex()` | z-index 管理 |
| `useNamespace(name)` | 类名前缀 |
| `useId()` | 生成唯一 id |
| `useResizeObserver()` | 监听 DOM 尺寸 |
| `useEventListener()` | 监听事件 |
| `useThrottleFn()` | 节流 |
| `useDebounceFn()` | 防抖 |
| `useDraggable()` | 拖拽(Dialog 等内部使用) |
---
## 9. 按需引入
### 9.1 自动按需(unplugin-vue-components)
```bash
npm install -D unplugin-vue-components
```
```ts
// vite.config.ts
import Components from 'unplugin-vue-components/vite'
import { MacrouiVueResolver } from 'unplugin-vue-components/resolvers'
export default {
plugins: [
Components({
resolvers: [MacrouiVueResolver()],
}),
],
}
```
### 9.2 手动按需(推荐用于 SSR)
```ts
import {
ElButton,
ElInput,
ElConfigProvider,
} from '@macroui/macroui-vue'
```
### 9.3 在 Webpack 中按需
```js
// babel.config.js
module.exports = {
plugins: [
['babel-plugin-import', {
libraryName: '@macroui/macroui-vue',
libraryDirectory: 'es',
style: true,
}, '@macroui/macroui-vue'],
],
}
```
---
## 10. SSR / Nuxt
### 10.1 Nuxt 3 配置
```ts
// nuxt.config.ts
export default defineNuxtConfig({
build: {
transpile: ['@macroui/macroui-vue'],
},
vite: {
optimizeDeps: {
include: ['@macroui/macroui-vue'],
},
},
css: [
'@macroui/macroui/dist/themes.css',
'@macroui/macroui/dist/styled.css',
'@macroui/macroui-vue/dist/style.css',
],
})
```
```ts
// plugins/macroui.ts
import MacrouiVue from '@macroui/macroui-vue'
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(MacrouiVue)
})
```
### 10.2 SSR 注意事项
- 引用的组件必须出现在 template 中,否则会在 server 端跳过
- 使用 `` 包裹需要 client 行为的组件(如 ElTooltip、ElPopover)
- 表单的 `el-form` SSR 推荐只渲染结构,校验放客户端
---
## 11. 浏览器支持
| 浏览器 | 版本 |
|--------|------|
| Chrome / Edge | 最近 2 年 |
| Firefox | 最近 2 年 |
| Safari | 14+ |
| iOS Safari | 14+ |
| Android Chrome | 90+ |
| IE | ❌ 不支持 |
支持 Vue 3(>= 3.4)。
---
## 12. 开发与构建
### 12.1 仓库克隆
```bash
git clone https://github.com/mobiui/macroui.git
cd macroui-vue
pnpm install
```
### 12.2 开发命令
```bash
# 库开发模式(监听源码,自动 build)
pnpm dev:lib
# 示例页面(examples/)
pnpm dev:demo
# 仅构建库
pnpm build:lib
# 完整构建(含 locale)
pnpm build:all
# 单元测试
pnpm test
pnpm test:watch
pnpm test:coverage
# E2E 测试
pnpm test:e2e
pnpm test:e2e:ui
# 代码风格
pnpm lint
# TypeScript 类型检查
pnpm typecheck
```
### 12.3 目录结构
```
macroui-vue/
├── examples/ # 示例项目(vite demo)
│ ├── pages/
│ ├── App.vue
│ ├── main.ts
│ └── vite.config.ts
├── packages/
│ ├── components/ # 90+ 组件
│ │ ├── ElButton/
│ │ │ ├── button.vue
│ │ │ ├── props.ts
│ │ │ └── index.ts
│ │ └── ...
│ ├── constants/ # 常量
│ │ ├── aria.ts
│ │ ├── date.ts
│ │ ├── form.ts
│ │ ├── key.ts
│ │ └── size.ts
│ ├── hooks/ # Hooks
│ ├── locale/ # i18n 语言包
│ │ ├── index.ts
│ │ └── lang/
│ ├── styles/ # 组件局部样式
│ └── utils/ # 工具函数
├── tests/
│ ├── unit/ # 单元测试 (vitest)
│ └── e2e/ # E2E 测试 (playwright)
├── styles/
│ └── index.scss # 全局样式入口
├── docs/ # 文档
├── dist/ # 构建产物
└── types/ # 全局类型
```
### 12.4 创建新组件
```bash
mkdir -p packages/components/ElNewComponent
touch packages/components/ElNewComponent/new-component.vue
touch packages/components/ElNewComponent/props.ts
touch packages/components/ElNewComponent/index.ts
```
**props.ts:**
```ts
import { buildProps } from '@macroui/macroui-vue'
import type { ExtractPropTypes, PropType } from 'vue'
export const newComponentProps = buildProps({
modelValue: {
type: [String, Number, Boolean],
default: '',
},
size: {
type: String,
values: ['large', 'default', 'small'],
default: 'default',
},
disabled: Boolean,
})
export const newComponentEmits = {
'update:modelValue': (value: any) => true,
}
export type NewComponentProps = ExtractPropTypes
export type NewComponentEmits = typeof newComponentEmits
```
**new-component.vue:**
```vue
```
**index.ts:**
```ts
import { withInstall } from '@macroui/macroui-vue'
import NewComponent from './new-component.vue'
export const ElNewComponent = withInstall(NewComponent)
export default ElNewComponent
```
### 12.5 添加到 packages/components/index.ts
```ts
export { ElNewComponent } from './ElNewComponent'
```
---
## 13. NPM 发布
```bash
# 1. 确认登录状态
npm whoami
# 2. 修改 package.json 中的 version(遵循 semver)
# major:破坏性变更
# minor:向下兼容的新功能
# patch:bugfix
# 3. 构建
pnpm build:lib
# 4. 发布
npm publish --access public
```
### 13.1 2FA Token 设置
如账户启用 2FA,需要 Granular Access Token:
1. 访问 https://www.npmjs.com/settings/tokens
2. 点击 **Generate New Token** → **Granular Access Token**
3. 配置:
- Token Name: `macroui-vue-publish`
- Organization: `@macroui`
- Permissions: **Publish packages** ✅
- **2FA Bypass**: ✅ **必须启用**
4. 生成 Token
```bash
npm config set //registry.npmjs.org/:_authToken=YOUR_GRANULAR_TOKEN
npm publish --access public
```
---
## 14. 项目结构
详见 [12.3 目录结构](#123-目录结构)。
---
## 15. 常见问题
### Q1: 样式不生效?
- ✅ 检查 CSS 加载顺序:`themes.css` → `styled.css` → `style.css`
- ✅ 确认 `` 已设置
- ✅ 检查 Tailwind config 中是否覆盖了类名前缀
- ✅ 检查 scoped 样式是否影响组件
### Q2: 组件不显示?
- ✅ 检查是否全局注册(`app.use(MacrouiVue)`)
- ✅ 检查是否局部注册 + 命名拼写
- ✅ 检查 `` 根节点是否就只有一个元素
### Q3: TypeScript 类型错误?
- ✅ 运行 `pnpm typecheck`
- ✅ 确保 `@types/node` 已安装
- ✅ 检查 `tsconfig.json` 中 `moduleResolution` 为 `bundler` 或 `node16`
### Q4: 主题切换无效?
- ✅ 注意 `data-theme` 是属性,不是 CSS class
- ✅ 自定义主题需匹配 HSL 格式(`H S% L%`)
### Q5: Dialog / Tooltip 不显示?
- ✅ 检查 z-index(默认 2000+),被遮挡时可显式设置 `z-index`
- ✅ 检查 `teleported` 是否为 `true`
### Q6: 国际化切换无效果?
- ✅ 使用 `el-config-provider` 包裹根组件
- ✅ 邮箱地址不应写在语言包
### Q7: 表单校验不生效?
- ✅ `el-form-item` 必须设置 `prop`
- ✅ `rules` 中使用 `{ required: true, message, trigger }`
- ✅ 校验触发使用 `await formRef.value?.validate()` 是 Promise 式
---
## 16. 许可证
[MIT License](LICENSE)
联系方式:peng.deyou@gmail.com
---
## 🔗 相关项目
- [@macroui/macroui](https://www.npmjs.com/package/@macroui/macroui) — MacroUI 主题与样式
- [@macroui/macroui-icons](https://www.npmjs.com/package/@macroui/macroui-icons) — 图标库
- [Element Plus](https://element-plus.org/) — API 兼容性参考
## 🔗 链接
- 仓库地址:https://github.com/mobiui/macroui
- 问题反馈:https://github.com/mobiui/macroui/issues