|
1 |
| -# winjs-plugin-example |
| 1 | +# winjs-plugin-element-ui |
2 | 2 |
|
3 |
| -Example plugin for WinJS. |
| 3 | +适配 WinJS 的 Element UI 插件,为 Vue 2 项目提供 Element UI 组件库的自动导入和配置支持。 |
4 | 4 |
|
5 | 5 | <p>
|
6 |
| - <a href="https://npmjs.com/package/winjs-plugin-example"> |
7 |
| - <img src="https://img.shields.io/npm/v/winjs-plugin-example?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> |
| 6 | + <a href="https://npmjs.com/package/@winner-fed/plugin-element-ui"> |
| 7 | + <img src="https://img.shields.io/npm/v/@winner-fed/plugin-element-ui?style=flat-square&colorA=564341&colorB=EDED91" alt="npm version" /> |
8 | 8 | </a>
|
9 | 9 | <img src="https://img.shields.io/badge/License-MIT-blue.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="license" />
|
10 |
| - <a href="https://npmcharts.com/compare/winjs-plugin-example?minimal=true"><img src="https://img.shields.io/npm/dm/winjs-plugin-example.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a> |
| 10 | + <a href="https://npmcharts.com/compare/@winner-fed/plugin-element-ui?minimal=true"><img src="https://img.shields.io/npm/dm/@winner-fed/plugin-element-ui.svg?style=flat-square&colorA=564341&colorB=EDED91" alt="downloads" /></a> |
11 | 11 | </p>
|
12 | 12 |
|
13 |
| -## Usage |
| 13 | +## 功能特性 |
14 | 14 |
|
15 |
| -Install: |
| 15 | +- 🚀 **自动导入**: 支持 Element UI 组件的按需自动导入 |
| 16 | +- 📦 **零配置**: 开箱即用,无需手动配置组件导入 |
| 17 | +- 🔧 **集成性**: 与 WinJS 框架深度集成 |
| 18 | +- 🎯 **Vue 2 兼容**: 专为 Vue 2 项目设计 |
| 19 | + |
| 20 | +## 安装 |
16 | 21 |
|
17 | 22 | ```bash
|
18 |
| -npm add winjs-plugin-example -D |
| 23 | +npm install @winner-fed/plugin-element-ui element-ui |
| 24 | +# 或者 |
| 25 | +yarn add @winner-fed/plugin-element-ui element-ui |
| 26 | +# 或者 |
| 27 | +pnpm add @winner-fed/plugin-element-ui element-ui |
| 28 | +``` |
| 29 | + |
| 30 | +## 快速开始 |
| 31 | + |
| 32 | +### 1. 在 `.winrc.ts` 中配置插件 |
| 33 | + |
| 34 | +```typescript |
| 35 | +import { defineConfig } from 'win'; |
| 36 | + |
| 37 | +export default defineConfig({ |
| 38 | + plugins: [ |
| 39 | + require.resolve('@winner-fed/plugin-element-ui') |
| 40 | + ], |
| 41 | + elementUI: { |
| 42 | + // 插件配置选项(可选) |
| 43 | + } |
| 44 | +}); |
19 | 45 | ```
|
20 | 46 |
|
21 |
| -Add plugin to your `.winrc.ts`: |
| 47 | +### 2. 在 Vue 组件中使用 |
| 48 | + |
| 49 | +插件会自动处理 Element UI 组件的导入,你可以直接在模板中使用: |
22 | 50 |
|
23 |
| -```ts |
24 |
| -// .winrc.ts |
| 51 | +```vue |
| 52 | +<template> |
| 53 | + <div> |
| 54 | + <el-button type="primary">主要按钮</el-button> |
| 55 | + <el-button type="success">成功按钮</el-button> |
| 56 | + <el-input v-model="input" placeholder="请输入内容"></el-input> |
| 57 | + <el-date-picker |
| 58 | + v-model="date" |
| 59 | + type="date" |
| 60 | + placeholder="选择日期"> |
| 61 | + </el-date-picker> |
| 62 | + </div> |
| 63 | +</template> |
| 64 | +
|
| 65 | +<script> |
25 | 66 | export default {
|
26 |
| - plugins: ['winjs-plugin-example'], |
27 |
| - // 开启配置 |
28 |
| - example: {} |
29 |
| -}; |
| 67 | + data() { |
| 68 | + return { |
| 69 | + input: '', |
| 70 | + date: '' |
| 71 | + } |
| 72 | + } |
| 73 | +} |
| 74 | +</script> |
| 75 | +``` |
| 76 | + |
| 77 | +## 配置选项 |
| 78 | + |
| 79 | +### elementUI |
| 80 | + |
| 81 | +类型:`object` |
| 82 | + |
| 83 | +Element UI 相关配置,目前支持的配置项: |
| 84 | + |
| 85 | +```typescript |
| 86 | +export default defineConfig({ |
| 87 | + elementUI: { |
| 88 | + // 未来可能会添加更多配置选项 |
| 89 | + } |
| 90 | +}); |
30 | 91 | ```
|
31 | 92 |
|
32 |
| -## Options |
| 93 | +## 工作原理 |
| 94 | + |
| 95 | +本插件通过以下方式实现 Element UI 的集成: |
| 96 | + |
| 97 | +1. **自动检测依赖**: 插件会自动检测项目中是否安装了 `element-ui` 包 |
| 98 | +2. **配置解析器**: 使用 `unplugin-vue-components` 的 `ElementUiResolver` 来处理组件的自动导入 |
| 99 | +3. **版本信息**: 自动读取 Element UI 的版本信息并注入到应用数据中 |
| 100 | +4. **按需导入**: 只导入实际使用的组件,减少打包体积 |
| 101 | + |
| 102 | +## 依赖要求 |
33 | 103 |
|
34 |
| -### foo |
| 104 | +- Vue 2.x |
| 105 | +- Element UI 2.15.13+ |
| 106 | +- WinJS 框架 |
35 | 107 |
|
36 |
| -Some description. |
| 108 | +### 示例代码 |
37 | 109 |
|
38 |
| -- Type: `string` |
39 |
| -- Default: `undefined` |
40 |
| -- Example: |
| 110 | +```vue |
| 111 | +<!-- src/pages/index.vue --> |
| 112 | +<template> |
| 113 | + <div> |
| 114 | + <h2>Welcome to WinJS + Element UI!</h2> |
| 115 | + <el-button type="primary">我是 Element UI 的按钮</el-button> |
| 116 | + <el-input v-model="message" placeholder="输入一些内容"></el-input> |
| 117 | + </div> |
| 118 | +</template> |
41 | 119 |
|
42 |
| -```js |
| 120 | +<script> |
43 | 121 | export default {
|
44 |
| - plugins: ['winjs-plugin-example'], |
45 |
| - // 开启配置 |
46 |
| - example: { |
47 |
| - foo: 'bar' |
| 122 | + data() { |
| 123 | + return { |
| 124 | + message: '' |
| 125 | + } |
48 | 126 | }
|
49 |
| -}; |
| 127 | +} |
| 128 | +</script> |
| 129 | +``` |
| 130 | + |
| 131 | +## 常见问题 |
| 132 | + |
| 133 | +### Q: 插件无法找到 Element UI 包? |
| 134 | + |
| 135 | +A: 确保已经安装了 `element-ui` 依赖: |
| 136 | + |
| 137 | +```bash |
| 138 | +npm install element-ui |
| 139 | +``` |
| 140 | + |
| 141 | +### Q: 组件样式没有生效? |
| 142 | + |
| 143 | +A: Element UI 的样式需要单独引入,可以在入口文件中添加: |
| 144 | + |
| 145 | +```javascript |
| 146 | +// 在 main.js 或入口文件中 |
| 147 | +import 'element-ui/lib/theme-chalk/index.css' |
50 | 148 | ```
|
51 | 149 |
|
52 |
| -## License |
| 150 | +### Q: 如何使用 Element UI 的按需导入? |
| 151 | + |
| 152 | +A: 插件已经自动配置了按需导入,你只需要在模板中使用组件即可,无需手动导入。 |
| 153 | + |
| 154 | +## 许可证 |
53 | 155 |
|
54 | 156 | [MIT](./LICENSE).
|
0 commit comments