条件编译
条件编译是用特殊的注释作为标记,在编译时根据这些特殊的注释,将注释里面的代码编译到不同平台。
写法 | 说明 |
---|---|
#ifdef | if defined 仅在某平台存在 |
#ifndef | if not defined 除了某平台均存在 |
%PLATFORM% | 平台名称 |
#ifend | 结尾,结束编译 |
#ifdef #ifndef 使用
<template>
<!-- #ifdef APP-PLUS -->
在App平台下会编译的代码
<!-- #endif -->
</template>
<script>
// #ifdef APP-PLUS
在App平台下会编译的代码
// #endif
// #ifndef APP-PLUS
除了在App以外平台 都会编译的代码
// #endif
// #ifdef APP-PLUS || HS
在 App平台 或 H5平台 下会编译的代码
// #endif
// #ifdef APP-PLUS && HS
App平台 且 H5平台 注意没有这种说法!!!
// #endif
</script>
<style>
/* #ifdef APP-PLUS */
在App平台下会编译的代码
/* #endif */
</style>
%PLATFORM%
值 | 平台 |
---|---|
APP-PLUS | App |
H5 | H5 |
MP-WEIXIN | 微信小程序 |
MP-ALIPAY | 支付宝小程序 |
MP-BAIDU | 百度小程序 |
MP | 微信小程序/支付宝小程序/百度小程序/字节跳动小程序/QQ小程序/360小程序 |
QUICKAPP-WEBVIEW | 快应用通用(包含联盟、华为) |
QUICKAPP-WEBVIEW-UNION | 快应用联盟 |
QUICKAPP-WEBVIEW-HUAWEI | 快应用华为 |
APP-PLUS-NVUE或APP-NVUE | App nvue |
点赞 评论 收藏 ~~ 有疑惑的小伙伴,可能是我表达不清楚,可以留言讨论,如有错误,也希望大家不吝指出。 ~~ 点赞 评论 收藏