#ifdef | 仅在某个平台上使用 |
#ifndef | 在除了这个平台的其他平台上使用(非此平台使用) |
#endif | 结束条件编译 |
H5 | H5 |
APP-PLUS | APP |
MP | 微信小程序/支付宝小程序/百度小程序/头条小程序/QQ小程序 |
MP-WEIXIN | 微信小程序 |
MP-ALIPAY | 支付宝小程序 |
MP-BAIDU | 百度小程序 |
MP-TOUTIAO | 头条小程序 |
MP-QQ | QQ小程序 |
APP-PLUS-NVUE | App nvue |
举例说明
1、js/css
H5端
/*#ifdef H5*/
console.log('H5')
/*#endif*/
小程序端
/*#ifdef MP*/
console.log('小程序')
/*#endif*/
2、html
H5端
<!-- #ifdef H5 -->
<view> H5 </view>
<!-- #endif -->
小程序端
<!-- #ifdef MP -->
<view> 小程序 </view>
<!-- #endif -->