@mc-markets/ui 1.0.91 → 1.0.92
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +218 -5
- package/USAGE_GUIDE.md +339 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/resolver.d.ts +26 -0
- package/dist/resolver.d.ts.map +1 -0
- package/package.json +8 -2
- package/packages/resolver.js +179 -0
package/README.md
CHANGED
|
@@ -10,14 +10,213 @@ Vue 3 组件库,基于 Element Plus 的自定义组件
|
|
|
10
10
|
|
|
11
11
|
演示站点通过 GitHub Actions 自动构建和部署,展示了所有组件的使用方法和效果。
|
|
12
12
|
|
|
13
|
-
##
|
|
13
|
+
## ✨ 特性
|
|
14
|
+
|
|
15
|
+
- 🎨 基于 Element Plus,保持一致的设计语言
|
|
16
|
+
- 🔧 支持全局注册和按需导入
|
|
17
|
+
- 📦 智能组件注册,自动转换 Element Plus 组件前缀 (el- → m-)
|
|
18
|
+
- 🚀 支持 unplugin-vue-components 自动导入
|
|
19
|
+
- 💪 TypeScript 支持
|
|
20
|
+
- 🎯 Tree-shaking 友好
|
|
21
|
+
|
|
22
|
+
## 🚀 安装
|
|
14
23
|
|
|
15
|
-
### 安装
|
|
16
24
|
```bash
|
|
17
|
-
npm
|
|
25
|
+
npm install @mc-markets/ui
|
|
26
|
+
# 或
|
|
27
|
+
yarn add @mc-markets/ui
|
|
28
|
+
# 或
|
|
29
|
+
pnpm add @mc-markets/ui
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 📦 使用方式
|
|
33
|
+
|
|
34
|
+
### 方式一:全局注册(推荐快速上手)
|
|
35
|
+
|
|
36
|
+
在 `main.js` 或 `main.ts` 中:
|
|
37
|
+
|
|
38
|
+
```javascript
|
|
39
|
+
import { createApp } from 'vue'
|
|
40
|
+
import App from './App.vue'
|
|
41
|
+
import McMarketsUI from '@mc-markets/ui'
|
|
42
|
+
import '@mc-markets/ui/dist/style.css'
|
|
43
|
+
|
|
44
|
+
const app = createApp(App)
|
|
45
|
+
app.use(McMarketsUI)
|
|
46
|
+
app.mount('#app')
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### 方式二:手动按需导入
|
|
50
|
+
|
|
51
|
+
```vue
|
|
52
|
+
<template>
|
|
53
|
+
<m-button type="primary">按钮</m-button>
|
|
54
|
+
<m-input v-model="value" placeholder="请输入" />
|
|
55
|
+
</template>
|
|
56
|
+
|
|
57
|
+
<script setup>
|
|
58
|
+
import { ref } from 'vue'
|
|
59
|
+
import { MButton, MInput } from '@mc-markets/ui'
|
|
60
|
+
import '@mc-markets/ui/dist/style.css'
|
|
61
|
+
|
|
62
|
+
const value = ref('')
|
|
63
|
+
</script>
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
### 方式三:自动按需导入(推荐)⭐
|
|
67
|
+
|
|
68
|
+
使用 `unplugin-vue-components` 和 `unplugin-auto-import` 实现零配置按需导入:
|
|
69
|
+
|
|
70
|
+
#### 1. 安装插件
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
npm install -D unplugin-vue-components unplugin-auto-import
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
#### 2. 配置 Vite
|
|
77
|
+
|
|
78
|
+
在 `vite.config.js` 或 `vite.config.ts` 中:
|
|
79
|
+
|
|
80
|
+
```javascript
|
|
81
|
+
import { defineConfig } from 'vite'
|
|
82
|
+
import vue from '@vitejs/plugin-vue'
|
|
83
|
+
import AutoImport from 'unplugin-auto-import/vite'
|
|
84
|
+
import Components from 'unplugin-vue-components/vite'
|
|
85
|
+
import { McMarketsUIResolver, getMcMarketsUIImports } from '@mc-markets/ui/resolver'
|
|
86
|
+
|
|
87
|
+
export default defineConfig({
|
|
88
|
+
plugins: [
|
|
89
|
+
vue(),
|
|
90
|
+
// 自动导入组件
|
|
91
|
+
Components({
|
|
92
|
+
resolvers: [
|
|
93
|
+
McMarketsUIResolver({
|
|
94
|
+
// prefix: 'm', // 组件前缀,默认 'm'
|
|
95
|
+
// importStyle: true // 自动导入样式,默认 true
|
|
96
|
+
})
|
|
97
|
+
]
|
|
98
|
+
}),
|
|
99
|
+
// 自动导入 API
|
|
100
|
+
AutoImport({
|
|
101
|
+
imports: [
|
|
102
|
+
'vue',
|
|
103
|
+
getMcMarketsUIImports() // 自动导入 Message, NotifiMessage 等 API
|
|
104
|
+
],
|
|
105
|
+
dts: 'src/auto-imports.d.ts'
|
|
106
|
+
})
|
|
107
|
+
]
|
|
108
|
+
})
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
#### 3. 配置 Webpack(Vue CLI)
|
|
112
|
+
|
|
113
|
+
在 `vue.config.js` 中:
|
|
114
|
+
|
|
115
|
+
```javascript
|
|
116
|
+
const AutoImport = require('unplugin-auto-import/webpack')
|
|
117
|
+
const Components = require('unplugin-vue-components/webpack')
|
|
118
|
+
const { McMarketsUIResolver, getMcMarketsUIImports } = require('@mc-markets/ui/resolver')
|
|
119
|
+
|
|
120
|
+
module.exports = {
|
|
121
|
+
configureWebpack: {
|
|
122
|
+
plugins: [
|
|
123
|
+
Components({
|
|
124
|
+
resolvers: [McMarketsUIResolver()]
|
|
125
|
+
}),
|
|
126
|
+
AutoImport({
|
|
127
|
+
imports: [
|
|
128
|
+
'vue',
|
|
129
|
+
getMcMarketsUIImports()
|
|
130
|
+
],
|
|
131
|
+
dts: 'src/auto-imports.d.ts'
|
|
132
|
+
})
|
|
133
|
+
]
|
|
134
|
+
}
|
|
135
|
+
}
|
|
18
136
|
```
|
|
19
137
|
|
|
20
|
-
|
|
138
|
+
#### 4. 直接使用组件(无需手动导入)
|
|
139
|
+
|
|
140
|
+
配置完成后,可以直接在模板中使用组件,无需手动导入:
|
|
141
|
+
|
|
142
|
+
```vue
|
|
143
|
+
<template>
|
|
144
|
+
<!-- 直接使用,无需导入 -->
|
|
145
|
+
<m-button type="primary" @click="showMessage">显示消息</m-button>
|
|
146
|
+
<m-input v-model="form.name" placeholder="请输入姓名" />
|
|
147
|
+
<m-select v-model="form.city">
|
|
148
|
+
<m-option label="北京" value="beijing" />
|
|
149
|
+
<m-option label="上海" value="shanghai" />
|
|
150
|
+
</m-select>
|
|
151
|
+
<m-date-picker v-model="form.date" />
|
|
152
|
+
</template>
|
|
153
|
+
|
|
154
|
+
<script setup>
|
|
155
|
+
import { ref } from 'vue'
|
|
156
|
+
|
|
157
|
+
// API 也会自动导入,可以直接使用
|
|
158
|
+
const form = ref({
|
|
159
|
+
name: '',
|
|
160
|
+
city: '',
|
|
161
|
+
date: ''
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
const showMessage = () => {
|
|
165
|
+
// Message 已自动导入
|
|
166
|
+
Message.success('操作成功!')
|
|
167
|
+
}
|
|
168
|
+
</script>
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
## 🎯 智能组件系统
|
|
172
|
+
|
|
173
|
+
本组件库实现了智能组件注册机制:
|
|
174
|
+
|
|
175
|
+
1. **自定义组件优先**:如果定义了自定义组件(如 `MButton`),会使用自定义版本
|
|
176
|
+
2. **Element Plus 回退**:未自定义的组件会自动从 Element Plus 导入
|
|
177
|
+
3. **前缀转换**:自动将 `el-*` 转换为 `m-*`(如 `<el-button>` → `<m-button>`)
|
|
178
|
+
4. **无缝集成**:可以混合使用自定义组件和 Element Plus 组件
|
|
179
|
+
|
|
180
|
+
### 可用组件
|
|
181
|
+
|
|
182
|
+
#### 自定义组件
|
|
183
|
+
- `MIcon` - 图标
|
|
184
|
+
- `MButton` - 按钮
|
|
185
|
+
- `MInput` - 输入框
|
|
186
|
+
- `MSelect` / `MOption` / `MOptionGroup` - 选择器
|
|
187
|
+
- `MForm` / `MFormItem` - 表单
|
|
188
|
+
- `MTable` / `MTableColumn` - 表格
|
|
189
|
+
- `MDatePicker` - 日期选择器
|
|
190
|
+
- `MPagination` - 分页
|
|
191
|
+
- `MRadio` / `MRadioGroup` / `MRadioButton` - 单选框
|
|
192
|
+
- `MSwitch` - 开关
|
|
193
|
+
- `MTag` - 标签
|
|
194
|
+
- `MAlert` - 警告
|
|
195
|
+
- `MDialog` - 对话框
|
|
196
|
+
- `MTooltip` - 文字提示
|
|
197
|
+
- `MEmpty` - 空状态
|
|
198
|
+
- `MBanner` - 横幅
|
|
199
|
+
- `MTabs` / `MTabPane` - 标签页
|
|
200
|
+
- `MTabCard` / `MTabCardItem` - 卡片标签页
|
|
201
|
+
- `MBreadcrumb` - 面包屑导航
|
|
202
|
+
|
|
203
|
+
#### Element Plus 组件(自动转换前缀)
|
|
204
|
+
所有 Element Plus 组件都可以通过 `m-` 前缀使用,例如:
|
|
205
|
+
- `MCarousel` / `MCarouselItem` - 走马灯
|
|
206
|
+
- `MCascader` - 级联选择器
|
|
207
|
+
- `MColorPicker` - 颜色选择器
|
|
208
|
+
- `MTree` / `MTreeSelect` - 树形控件
|
|
209
|
+
- `MUpload` - 上传
|
|
210
|
+
- `MProgress` - 进度条
|
|
211
|
+
- 等等...
|
|
212
|
+
|
|
213
|
+
#### API 方法
|
|
214
|
+
- `Message` - 消息提示
|
|
215
|
+
- `NotifiMessage` - 通知消息
|
|
216
|
+
- `MMessageBox` - 消息弹框
|
|
217
|
+
|
|
218
|
+
## 🛠️ 文档开发
|
|
219
|
+
|
|
21
220
|
```bash
|
|
22
221
|
# 安装依赖
|
|
23
222
|
npm install
|
|
@@ -25,6 +224,20 @@ npm install
|
|
|
25
224
|
# 启动开发服务器
|
|
26
225
|
npm run dev
|
|
27
226
|
|
|
28
|
-
#
|
|
227
|
+
# 构建组件库
|
|
228
|
+
npm run build
|
|
229
|
+
|
|
230
|
+
# 构建演示站点
|
|
231
|
+
npm run build:demo
|
|
232
|
+
|
|
233
|
+
# 发布到 npm
|
|
29
234
|
npm run publish:lib
|
|
30
235
|
```
|
|
236
|
+
|
|
237
|
+
## 📄 License
|
|
238
|
+
|
|
239
|
+
MIT
|
|
240
|
+
|
|
241
|
+
## 🤝 贡献
|
|
242
|
+
|
|
243
|
+
欢迎提交 Issue 和 Pull Request!
|
package/USAGE_GUIDE.md
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
1
|
+
# @mc-markets/ui 使用指南
|
|
2
|
+
|
|
3
|
+
## 自动按需导入配置示例
|
|
4
|
+
|
|
5
|
+
### Vite 项目完整配置示例
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
// vite.config.js
|
|
9
|
+
import { defineConfig } from 'vite'
|
|
10
|
+
import vue from '@vitejs/plugin-vue'
|
|
11
|
+
import AutoImport from 'unplugin-auto-import/vite'
|
|
12
|
+
import Components from 'unplugin-vue-components/vite'
|
|
13
|
+
import { McMarketsUIResolver, getMcMarketsUIImports } from '@mc-markets/ui/resolver'
|
|
14
|
+
|
|
15
|
+
export default defineConfig({
|
|
16
|
+
plugins: [
|
|
17
|
+
vue(),
|
|
18
|
+
|
|
19
|
+
// 自动导入组件
|
|
20
|
+
Components({
|
|
21
|
+
resolvers: [
|
|
22
|
+
// 自定义配置
|
|
23
|
+
McMarketsUIResolver({
|
|
24
|
+
prefix: 'm', // 组件前缀,默认 'm'
|
|
25
|
+
importStyle: true // 自动导入样式,默认 true
|
|
26
|
+
})
|
|
27
|
+
],
|
|
28
|
+
// 生成类型声明文件
|
|
29
|
+
dts: 'src/components.d.ts',
|
|
30
|
+
// 自动导入的组件目录
|
|
31
|
+
dirs: ['src/components'],
|
|
32
|
+
// 组件的有效文件扩展名
|
|
33
|
+
extensions: ['vue'],
|
|
34
|
+
}),
|
|
35
|
+
|
|
36
|
+
// 自动导入 API
|
|
37
|
+
AutoImport({
|
|
38
|
+
imports: [
|
|
39
|
+
'vue',
|
|
40
|
+
'vue-router',
|
|
41
|
+
// 自动导入 @mc-markets/ui 的 API
|
|
42
|
+
getMcMarketsUIImports()
|
|
43
|
+
],
|
|
44
|
+
// 生成类型声明文件
|
|
45
|
+
dts: 'src/auto-imports.d.ts',
|
|
46
|
+
// 自动导入 Vue 相关函数
|
|
47
|
+
eslintrc: {
|
|
48
|
+
enabled: true, // 生成 ESLint 配置
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
]
|
|
52
|
+
})
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### TypeScript 配置
|
|
56
|
+
|
|
57
|
+
确保 `tsconfig.json` 包含生成的类型声明文件:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"compilerOptions": {
|
|
62
|
+
// ... 其他配置
|
|
63
|
+
},
|
|
64
|
+
"include": [
|
|
65
|
+
"src/**/*",
|
|
66
|
+
"src/auto-imports.d.ts",
|
|
67
|
+
"src/components.d.ts"
|
|
68
|
+
]
|
|
69
|
+
}
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
### 使用示例
|
|
73
|
+
|
|
74
|
+
配置完成后,可以直接使用组件和 API,无需手动导入:
|
|
75
|
+
|
|
76
|
+
```vue
|
|
77
|
+
<template>
|
|
78
|
+
<div class="container">
|
|
79
|
+
<!-- 组件自动导入 -->
|
|
80
|
+
<m-button type="primary" @click="handleClick">
|
|
81
|
+
点击我
|
|
82
|
+
</m-button>
|
|
83
|
+
|
|
84
|
+
<m-input
|
|
85
|
+
v-model="formData.username"
|
|
86
|
+
placeholder="请输入用户名"
|
|
87
|
+
clearable
|
|
88
|
+
/>
|
|
89
|
+
|
|
90
|
+
<m-select v-model="formData.city" placeholder="请选择城市">
|
|
91
|
+
<m-option label="北京" value="beijing" />
|
|
92
|
+
<m-option label="上海" value="shanghai" />
|
|
93
|
+
<m-option label="深圳" value="shenzhen" />
|
|
94
|
+
</m-select>
|
|
95
|
+
|
|
96
|
+
<m-date-picker
|
|
97
|
+
v-model="formData.date"
|
|
98
|
+
type="date"
|
|
99
|
+
placeholder="选择日期"
|
|
100
|
+
/>
|
|
101
|
+
|
|
102
|
+
<m-table :data="tableData">
|
|
103
|
+
<m-table-column prop="name" label="姓名" />
|
|
104
|
+
<m-table-column prop="age" label="年龄" />
|
|
105
|
+
</m-table>
|
|
106
|
+
</div>
|
|
107
|
+
</template>
|
|
108
|
+
|
|
109
|
+
<script setup>
|
|
110
|
+
// ref, reactive 等 Vue API 自动导入
|
|
111
|
+
// Message, NotifiMessage 等 UI API 自动导入
|
|
112
|
+
const formData = reactive({
|
|
113
|
+
username: '',
|
|
114
|
+
city: '',
|
|
115
|
+
date: ''
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const tableData = ref([
|
|
119
|
+
{ name: '张三', age: 28 },
|
|
120
|
+
{ name: '李四', age: 32 }
|
|
121
|
+
])
|
|
122
|
+
|
|
123
|
+
// 直接使用 Message API,无需导入
|
|
124
|
+
const handleClick = () => {
|
|
125
|
+
Message.success('操作成功!')
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// 使用 NotifiMessage
|
|
129
|
+
const showNotification = () => {
|
|
130
|
+
NotifiMessage({
|
|
131
|
+
title: '通知',
|
|
132
|
+
message: '这是一条通知消息',
|
|
133
|
+
type: 'success'
|
|
134
|
+
})
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
// 使用 MessageBox
|
|
138
|
+
const showConfirm = async () => {
|
|
139
|
+
try {
|
|
140
|
+
await MMessageBox.confirm('确定要删除吗?', '提示')
|
|
141
|
+
Message.success('已删除')
|
|
142
|
+
} catch {
|
|
143
|
+
Message.info('已取消')
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
</script>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Webpack/Vue CLI 项目配置
|
|
150
|
+
|
|
151
|
+
### 安装依赖
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
npm install -D unplugin-auto-import unplugin-vue-components
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
### 配置
|
|
158
|
+
|
|
159
|
+
```javascript
|
|
160
|
+
// vue.config.js
|
|
161
|
+
const AutoImport = require('unplugin-auto-import/webpack')
|
|
162
|
+
const Components = require('unplugin-vue-components/webpack')
|
|
163
|
+
const { McMarketsUIResolver, getMcMarketsUIImports } = require('@mc-markets/ui/resolver')
|
|
164
|
+
|
|
165
|
+
module.exports = {
|
|
166
|
+
configureWebpack: {
|
|
167
|
+
plugins: [
|
|
168
|
+
Components({
|
|
169
|
+
resolvers: [McMarketsUIResolver()],
|
|
170
|
+
dts: 'src/components.d.ts'
|
|
171
|
+
}),
|
|
172
|
+
AutoImport({
|
|
173
|
+
imports: [
|
|
174
|
+
'vue',
|
|
175
|
+
'vue-router',
|
|
176
|
+
getMcMarketsUIImports()
|
|
177
|
+
],
|
|
178
|
+
dts: 'src/auto-imports.d.ts',
|
|
179
|
+
eslintrc: {
|
|
180
|
+
enabled: true
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Nuxt 3 项目配置
|
|
189
|
+
|
|
190
|
+
```javascript
|
|
191
|
+
// nuxt.config.ts
|
|
192
|
+
import { McMarketsUIResolver, getMcMarketsUIImports } from '@mc-markets/ui/resolver'
|
|
193
|
+
|
|
194
|
+
export default defineNuxtConfig({
|
|
195
|
+
modules: [
|
|
196
|
+
['unplugin-vue-components/nuxt', {
|
|
197
|
+
resolvers: [McMarketsUIResolver()]
|
|
198
|
+
}],
|
|
199
|
+
['unplugin-auto-import/nuxt', {
|
|
200
|
+
imports: [
|
|
201
|
+
'vue',
|
|
202
|
+
getMcMarketsUIImports()
|
|
203
|
+
]
|
|
204
|
+
}]
|
|
205
|
+
]
|
|
206
|
+
})
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## 混合使用自定义组件和 Element Plus 组件
|
|
210
|
+
|
|
211
|
+
由于智能注册机制,你可以混合使用:
|
|
212
|
+
|
|
213
|
+
```vue
|
|
214
|
+
<template>
|
|
215
|
+
<!-- 使用自定义的 MButton -->
|
|
216
|
+
<m-button type="primary">自定义按钮</m-button>
|
|
217
|
+
|
|
218
|
+
<!-- 使用转换前缀后的 Element Plus 组件 -->
|
|
219
|
+
<m-carousel height="200px">
|
|
220
|
+
<m-carousel-item v-for="item in 4" :key="item">
|
|
221
|
+
<h3>{{ item }}</h3>
|
|
222
|
+
</m-carousel-item>
|
|
223
|
+
</m-carousel>
|
|
224
|
+
|
|
225
|
+
<!-- 使用 Element Plus 的 Tree 组件 -->
|
|
226
|
+
<m-tree :data="treeData" />
|
|
227
|
+
|
|
228
|
+
<!-- 使用自定义的 Table 组件 -->
|
|
229
|
+
<m-table :data="tableData">
|
|
230
|
+
<m-table-column prop="name" label="姓名" />
|
|
231
|
+
</m-table>
|
|
232
|
+
</template>
|
|
233
|
+
```
|
|
234
|
+
|
|
235
|
+
## 常见问题
|
|
236
|
+
|
|
237
|
+
### Q: 为什么组件没有自动导入?
|
|
238
|
+
|
|
239
|
+
**A:** 检查以下几点:
|
|
240
|
+
1. 确保已正确安装和配置 `unplugin-vue-components` 和 `unplugin-auto-import`
|
|
241
|
+
2. 重启开发服务器
|
|
242
|
+
3. 检查组件名称是否以 `M` 或 `m-` 开头
|
|
243
|
+
4. 查看生成的 `components.d.ts` 文件确认组件已注册
|
|
244
|
+
|
|
245
|
+
### Q: TypeScript 类型提示不生效?
|
|
246
|
+
|
|
247
|
+
**A:**
|
|
248
|
+
1. 确保 `tsconfig.json` 包含了生成的 `.d.ts` 文件
|
|
249
|
+
2. 重启 VS Code 或 IDE
|
|
250
|
+
3. 运行 `npm run dev` 让插件生成类型文件
|
|
251
|
+
|
|
252
|
+
### Q: 样式没有加载?
|
|
253
|
+
|
|
254
|
+
**A:**
|
|
255
|
+
1. 如果使用自动导入,确保 `McMarketsUIResolver` 的 `importStyle` 选项为 `true`(默认)
|
|
256
|
+
2. 或者手动在 `main.js` 中导入:
|
|
257
|
+
```javascript
|
|
258
|
+
import '@mc-markets/ui/dist/style.css'
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
### Q: 如何使用 Element Plus 的原始组件?
|
|
262
|
+
|
|
263
|
+
**A:** 有两种方式:
|
|
264
|
+
1. 使用 `m-` 前缀(推荐):`<m-carousel>`
|
|
265
|
+
2. 手动导入原始组件:
|
|
266
|
+
```javascript
|
|
267
|
+
import { ElCarousel } from 'element-plus'
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
### Q: 如何自定义组件前缀?
|
|
271
|
+
|
|
272
|
+
**A:** 在 resolver 配置中修改:
|
|
273
|
+
```javascript
|
|
274
|
+
McMarketsUIResolver({
|
|
275
|
+
prefix: 'custom' // 将前缀改为 'custom'
|
|
276
|
+
})
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## 高级配置
|
|
280
|
+
|
|
281
|
+
### 按需加载样式
|
|
282
|
+
|
|
283
|
+
如果你想更精细地控制样式加载:
|
|
284
|
+
|
|
285
|
+
```javascript
|
|
286
|
+
Components({
|
|
287
|
+
resolvers: [
|
|
288
|
+
McMarketsUIResolver({
|
|
289
|
+
importStyle: false // 禁用自动导入样式
|
|
290
|
+
})
|
|
291
|
+
]
|
|
292
|
+
})
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
然后在需要的地方手动导入:
|
|
296
|
+
```javascript
|
|
297
|
+
import '@mc-markets/ui/dist/style.css'
|
|
298
|
+
```
|
|
299
|
+
|
|
300
|
+
### 结合 Element Plus 使用
|
|
301
|
+
|
|
302
|
+
如果你的项目同时使用 Element Plus 和本组件库:
|
|
303
|
+
|
|
304
|
+
```javascript
|
|
305
|
+
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
|
|
306
|
+
import { McMarketsUIResolver } from '@mc-markets/ui/resolver'
|
|
307
|
+
|
|
308
|
+
Components({
|
|
309
|
+
resolvers: [
|
|
310
|
+
McMarketsUIResolver(), // 优先使用自定义组件
|
|
311
|
+
ElementPlusResolver() // 回退到 Element Plus
|
|
312
|
+
]
|
|
313
|
+
})
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
## 性能优化建议
|
|
317
|
+
|
|
318
|
+
1. **启用 Tree Shaking**:使用自动导入可以实现最佳的 Tree Shaking 效果
|
|
319
|
+
2. **按需加载**:只导入使用的组件,减小打包体积
|
|
320
|
+
3. **生产环境优化**:
|
|
321
|
+
```javascript
|
|
322
|
+
build: {
|
|
323
|
+
minify: 'terser',
|
|
324
|
+
terserOptions: {
|
|
325
|
+
compress: {
|
|
326
|
+
drop_console: true,
|
|
327
|
+
drop_debugger: true
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
## 更多资源
|
|
334
|
+
|
|
335
|
+
- [在线演示](https://daboluoxigua.github.io/mc-markets-ui/)
|
|
336
|
+
- [npm 仓库](https://www.npmjs.com/package/@mc-markets/ui)
|
|
337
|
+
- [GitHub](https://github.com/daboluoxigua/mc-markets-ui)
|
|
338
|
+
- [Element Plus 文档](https://element-plus.org/)
|
|
339
|
+
|