uniapp中的条件编译
1.组件(view类)的条件编译
<!-- #ifdef MP-WEIXIN -->
<button>此代码仅在微信小程序平台出现</button>
<!-- #endif -->
<!-- #ifndef H5 -->
<button>此代码不会在H5平台出现</button>
<!-- #endif -->
<!-- #ifdef APP-PLUS || H5 -->
<button>此代码会在App和H5平台出现</button>
<!-- #endif -->
2.样式(css类)的条件编译
/* #ifdef APP-PLUS */
/* 仅在app平台显示 */
.abc{
color:#fff;
}
/* #endif */
3.api(js类)的条件编译
// #ifdef APP-PLUS
console.log('此代码仅在App平台显示');
// #endif
// #ifndef H5
console.log("此代码不会在H5平台显示");
// #endif
// #ifdef APP-PLUS || H5
console.log("此代码会在App平台和H5平台显示");
// #endif
4.pages.json 的条件编译
// #ifdef APP-PLUS
{
"path":"pages/index/index"
}
// #endif