|
7 | 7 | ## 引入组件
|
8 | 8 |
|
9 | 9 | 1. 通过 [useExtendedLib 扩展库](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#useExtendedLib) 的方式引入,这种方式引入的组件将不会计入代码包大小。
|
10 |
| -2. 可以通过[npm](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)方式下载构建,npm包名为`weui-miniprogram` |
11 | 10 |
|
12 | 11 |
|
13 |
| -## 如何使用 |
| 12 | + ```json |
| 13 | + // app.json |
| 14 | + { |
| 15 | + "useExtendedLib": { |
| 16 | + "weui": true // weui 会自动更新到最新版本 |
| 17 | + } |
| 18 | + } |
| 19 | + ``` |
14 | 20 |
|
15 |
| -首先要在 app.wxss 里面引入 weui.wxss,如果是通过 npm 引入,需要先构建 npm(“工具”菜单 --> “构建 npm”) |
| 21 | + ```json |
| 22 | + // app.json |
| 23 | + { |
| 24 | + "useExtendedLib": { |
| 25 | + "weui": "1.3.61" // 固定 weui 版本 |
| 26 | + } |
| 27 | + } |
| 28 | + ``` |
16 | 29 |
|
17 |
| -**通过 [useExtendedLib 扩展库](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#useExtendedLib) 的方式引入,可省略 import 步骤** |
18 | 30 |
|
19 |
| -```css |
20 |
| -@import 'weui-miniprogram/weui-wxss/dist/style/weui.wxss'; |
21 |
| -``` |
| 31 | +2. 可以通过[npm](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)方式下载构建,npm包为[weui-miniprogram](https://www.npmjs.com/package/weui-miniprogram) |
22 | 32 |
|
23 |
| -然后可以在页面中引入 dialog 弹窗组件 |
24 |
| -1. 首先在页面的 json 文件加入 usingComponents 配置字段 |
25 |
| -``` |
26 |
| -{ |
27 |
| - "usingComponents": { |
28 |
| - "mp-dialog": "weui-miniprogram/dialog/dialog" |
29 |
| - } |
30 |
| -} |
31 |
| -``` |
| 33 | + ```bash |
| 34 | + npm i weui-miniprogram -D |
| 35 | + ``` |
32 | 36 |
|
33 |
| -2. 然后可以在对应页面的 wxml 中直接使用该组件 |
| 37 | + 通过 npm 引入后需要先构建 npm(“工具”菜单 --> “构建 npm”) |
34 | 38 |
|
35 |
| -```html |
36 |
| -<mp-dialog title="test" show="{{true}}" bindbuttontap="tapDialogButton" buttons="{{buttons}}"> |
37 |
| - <view>test content</view> |
38 |
| -</mp-dialog> |
39 |
| -``` |
| 39 | +## 如何使用 |
40 | 40 |
|
41 |
| -```js |
42 |
| -Page({ |
43 |
| - data: { |
44 |
| - buttons: [{text: '取消'}, {text: '确认'}] |
45 |
| - } |
46 |
| -}) |
47 |
| -``` |
| 41 | +1. 首先要在 app.wxss 里面引入 weui.wxss |
| 42 | + |
| 43 | + **通过 [useExtendedLib 扩展库](https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html#useExtendedLib) 的方式引入,可省略 import 步骤** |
| 44 | + |
| 45 | + ```css |
| 46 | + @import '/miniprogram_npm/weui-miniprogram/weui-wxss/dist/style/weui.wxss'; |
| 47 | + ``` |
| 48 | + |
| 49 | +1. 在页面 json 中引入 dialog 弹窗组件 |
| 50 | + ```json |
| 51 | + // 页面 json |
| 52 | + { |
| 53 | + "usingComponents": { |
| 54 | + "mp-dialog": "weui-miniprogram/dialog/dialog" |
| 55 | + } |
| 56 | + } |
| 57 | + ``` |
| 58 | + |
| 59 | +1. 在对应页面的 wxml 中直接使用该组件 |
| 60 | + |
| 61 | + ```html |
| 62 | + <!-- 页面 wxml --> |
| 63 | + <mp-dialog title="test" show="{{true}}" bindbuttontap="tapDialogButton" buttons="{{buttons}}"> |
| 64 | + <view>test content</view> |
| 65 | + </mp-dialog> |
| 66 | + ``` |
| 67 | + |
| 68 | + ```js |
| 69 | + // 页面 js |
| 70 | + Page({ |
| 71 | + data: { |
| 72 | + buttons: [{text: '取消'}, {text: '确认'}] |
| 73 | + } |
| 74 | + }) |
| 75 | + ``` |
48 | 76 |
|
49 | 77 | 完整的组件的使用文档请参考具体的组件的文档。
|
50 | 78 |
|
|
0 commit comments