22
33本节介绍如何在` uni-app ` 项目中安装、配置并使用 ` Wot Design Uni ` 。
44
5+
6+
7+ ## 安装
58:::warning 关于安装
69` Wot Design Uni ` 提供了` uni_modules ` 和` npm ` 两种安装方式,按需选择。
710- 使用` uni_modules ` 安装无需额外配置,即插即用,但是每次更新组件库需要处理代码差异(一般直接覆盖就可以)。
811- 使用` npm ` 安装需要额外配置,更新组件库时无需处理代码差异。
912:::
1013
11- ## uni_modules 安装
12-
13- ` Wot Design Uni ` 支持 [ uni_modules] ( https://uniapp.dcloud.net.cn/plugin/uni_modules.html#uni-modules ) 规范,已经上架到 uni-app 的插件市场。
14-
15- 在` uni-app插件市场 ` 选择使用` HBuildX ` 导入,或者选择手动在src目录下创建uni_modules文件夹并将` Wot Design Uni ` 解压到uni_modules中,结构如下:
16- ```
17- - uni_modules
18- - - - wot-design-uni
19- ```
20-
21- 下载地址:<a href =" https://ext.dcloud.net.cn/plugin?id=13889 " ><span >wot-design-uni</span ></a >
22-
23-
24- ## npm 安装
14+ ### npm 安装
2515
2616::: code-group
2717``` bash [npm]
@@ -37,7 +27,28 @@ pnpm add wot-design-uni
3727```
3828:::
3929
40- ### 配置easycom自动引入组件<el-tag type =" primary " style =" vertical-align : middle ;margin-left :8px ;" effect =" dark " >自动引入方案1</el-tag >
30+
31+ ### uni_modules 安装
32+
33+ ` Wot Design Uni ` 支持 [ uni_modules] ( https://uniapp.dcloud.net.cn/plugin/uni_modules.html#uni-modules ) 规范,已经上架到 uni-app 的插件市场。
34+
35+ 在` uni-app插件市场 ` 选择使用` HBuildX ` 导入,或者选择手动在src目录下创建uni_modules文件夹并将` Wot Design Uni ` 解压到uni_modules中,结构如下:
36+ ```
37+ - uni_modules
38+ - - - wot-design-uni
39+ ```
40+
41+ 下载地址:<a href =" https://ext.dcloud.net.cn/plugin?id=13889 " ><span >wot-design-uni</span ></a >
42+
43+
44+ ## 配置
45+
46+ ### 导入组件
47+ ::: tip 提醒
48+ 使用 ` uni_modules ` 安装时` Wot Design Uni ` 的组件天然支持` easycom ` 规范,无需额外配置就可以自动引入组件,而使用 ` npm安装 ` 需按照此步骤配置,以下两种方案二选一即可。
49+ :::
50+
51+ #### 配置easycom自动引入组件<el-tag type =" primary " style =" vertical-align : middle ;margin-left :8px ;" effect =" dark " >方案1</el-tag >
4152传统vue组件,需要安装、引用、注册,三个步骤后才能使用组件。` easycom ` 将其精简为一步。
4253只要组件路径符合规范(具体见[ easycom] ( https://uniapp.dcloud.net.cn/collocation/pages.html#easycom ) ),就可以不用引用、注册,直接在页面中使用。
4354
@@ -63,12 +74,12 @@ pnpm add wot-design-uni
6374}
6475```
6576
66- ### 基于vite配置自动引入组件<el-tag type =" primary " style =" vertical-align : middle ;margin-left :8px ;" effect =" dark " >自动引入方案2 </el-tag >
77+ #### 基于vite配置自动引入组件<el-tag type =" primary " style =" vertical-align : middle ;margin-left :8px ;" effect =" dark " >方案2 </el-tag >
6778如果不熟悉` easycom ` ,也可以通过[ @uni-helper/vite-plugin-uni-components ] ( https://github.com/uni-helper/vite-plugin-uni-components ) 实现组件的自动引入。
6879
6980:::tip 提醒
7081- 推荐使用@uni-helper/vite-plugin-uni-components @0.0.9及以上版本,因为在0.0.9版本开始其内置了` wot-design-uni ` 的` resolver ` 。
71- - 如果使用此方案时控制台打印很多` Sourcemap for points to missing source files ` ,可以尝试将vite版本升级至4 .5.x。
82+ - 如果使用此方案时控制台打印很多` Sourcemap for points to missing source files ` ,可以尝试将vite版本升级至 ` 4 .5.x` 以上版本 。
7283:::
7384
7485::: code-group
@@ -85,37 +96,6 @@ pnpm add @uni-helper/vite-plugin-uni-components -D
8596```
8697:::
8798
88- *** @uni-helper/vite-plugin-uni-components 0.0.8及之前版本***
89- ``` ts
90- // vite.config.ts
91- import { defineConfig } from " vite" ;
92- import uni from " @dcloudio/vite-plugin-uni" ;
93-
94- import Components , { kebabCase } from ' @uni-helper/vite-plugin-uni-components'
95-
96- export default defineConfig ({
97- plugins: [
98- // make sure put it before `Uni()`
99- Components ({
100- resolvers: [
101- {
102- type: ' component' ,
103- resolve : (name : string ) => {
104- if (name .match (/ ^ Wd[A-Z ] / )) {
105- const compName = kebabCase (name )
106- return {
107- name ,
108- from: ` wot-design-uni/components/${compName }/${compName }.vue ` ,
109- }
110- }
111- },
112- }
113- ]
114- }), uni ()],
115- });
116- ```
117-
118- *** @uni-helper/vite-plugin-uni-components 0.0.9及以后版本***
11999``` ts
120100// vite.config.ts
121101import { defineConfig } from " vite" ;
@@ -133,7 +113,6 @@ export default defineConfig({
133113 }), uni ()],
134114});
135115```
136- #### UI 组件类型提示
137116
138117如果你使用 ` pnpm ` ,请在根目录下创建一个 ` .npmrc ` 文件,参见[ issue] ( https://github.com/antfu/unplugin-vue-components/issues/389 ) 。
139118
@@ -145,7 +124,7 @@ public-hoist-pattern[]=@vue*
145124```
146125
147126
148- ## Volar 支持< el-tag type = " primary " style = " vertical-align : middle ; margin-left : 8 px ; " effect = " dark " >推荐</ el-tag >
127+ ## Volar 支持
149128如果您使用 ` Volar ` ,请在 ` tsconfig.json ` 中通过 ` compilerOptions.type ` 指定全局组件类型。
150129::: tip
151130cli项目使用` uni_modules ` 安装无需配置,对` Volar ` 的支持自动生效,` HbuildX ` 项目不支持此配置,故此步骤仅在` cli ` 项目使用` npm ` 安装时需要配置。
@@ -166,7 +145,3 @@ cli项目使用`uni_modules`安装无需配置,对`Volar`的支持自动生效
166145``` html
167146<wd-toast ></wd-toast >
168147```
169-
170- :::tip 提示
171- 使用uni_modules 安装时` Wot Design Uni ` 的组件天然支持` easycom ` 规范,无需额外配置就可以自动引入组件,而使用npm安装需要自行配置` easycom ` 或` @uni-helper/vite-plugin-uni-components ` 。
172- :::
0 commit comments