语法:以 #ifdef 或 #ifndef 加 %PLATFORM% 开头,以 #endif 结尾
- #ifdef:if defined 仅在某平台存在
- #ifndef:if not defined 除了某平台均存在
- %PLATFORM%:平台名称
// 仅出现在 App 平台下的代码
#ifdef APP-PLUS
需条件编译的代码
#endif
// 除了 H5 平台,其它平台均存在的代码
#ifndef H5
需条件编译的代码
#endif
// 在 H5 平台或微信小程序平台存在的代码
#ifdef H5 || MP-WEIXIN
需条件编译的代码
#endif
//css样式中
page{
padding-top:24rpx;
/* #ifdef H5 */
padding-top:34rpx;
/* #endif */
}
//.vue页面中
<template>
<!-- #ifdef APP-PLUS -->
<view>NFC扫码</view>
<!-- #endif -->
</template>
//page.json页面中
//json文件中
//API 的条件编译
//生命周期中
//methods方法中
mounted(){
// #ifdef APP-PLUS
//APP更新
this.checkUpdate();
//#endif
}