uniapp提供了非常强大的条件编译功能
你可以在在h5中,小程序中,app中,分别执行不同的代码 html标签 js css均可用
解决了多端适配的问题 简单高效
可以使用的平台有 ()https://uniapp.dcloud.io/platform?id=preprocessor
html标签写法
<!-- #ifdef MP-WEIXIN || H5 --> 微信中和html5中显示
<button @getuserinfo="getUserInfo">获取用户信息</button>
<!-- #endif -->
js写法
// #ifdef APP-PLUS 在app中显示
const uuid = plus.device.uuid;
// #endif
css写法
/* #ifdef MP-ALIPAY*/
input {
padding: 0;
}
/* #endif */
通过 注释 #ifdef 你需要显示的平台
代码
注释 #endif
这种格式即可完成条件编译 记得加endif