主要使用条件编译,见:uni-app判断运行的平台
1.存放目录(官方推荐的是在根目录或者src目录下,也可以在vue.config.js文件中配置为其他目录):
平台 | 支持情况 | 小程序组件存放目录 |
H5 | 支持微信小程序组件(2.4.7+) | wxcomponents |
App(不含nvue) | 支持微信小程序组件 | wxcomponents |
微信小程序 | 支持微信小程序组件 | wxcomponents |
支付宝小程序 | 支持支付宝小程序组件 | mycomponents |
百度小程序 | 支持百度小程序组件 | swancomponents |
字节跳动小程序、飞书小程序 | 支持字节跳动小程序、飞书小程序组件 | ttcomponents |
QQ小程序 | 支持QQ小程序组件 | wxcomponents |
快手小程序 | 支持快手小程序组件 | kscomponents |
2.引用+注册
在 pages.json
对应页面的 style -> usingComponents 引入组件:
3.使用
或者直接使用<uni-app/>标签使用。
作者:꧁执笔小白꧂