王座视角 發表於 2022-9-7 10:11:00

uni-app 条件编译

<p>条件编译可以使一套代码,在不同平台下执行不同的部份。比如在APP内执行A,在小程序内执行B。</p>
<p>条件编译可以出现在:template、style、script 三个模块内。在三个模块内编译代码也不一样。</p>
<p>比如在template内,输入ifdef 按回车,代码如下:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(51, 102, 255, 1)">&lt;!-- #ifdef APP-PLUS --&gt;</span><span style="color: rgba(0, 0, 0, 1)">
在APP平台下执行这部份
</span><span style="color: rgba(51, 102, 255, 1)">&lt;!-- #endif --&gt;</span></pre>
</div>
<p>比如在style内,输入ifdef按回车,代码如下:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(51, 102, 255, 1)">/* #ifdef APP-PLUS */</span><span style="color: rgba(0, 0, 0, 1)">
.appstyle{
}
</span><span style="color: rgba(51, 102, 255, 1)">/* #endif */</span></pre>
</div>
<p>比如在script内,输入ifdef按回车,代码如下:&nbsp;</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(51, 102, 255, 1)">// #ifdef APP-PLUS</span>
console.log('APP下执行'<span style="color: rgba(0, 0, 0, 1)">);
</span><span style="color: rgba(51, 102, 255, 1)">// #endif</span></pre>
</div>
<p>&nbsp;</p>
<h3>一、其中<strong><span style="color: rgba(51, 102, 255, 1)">APP-PLUS</span></strong>表示APP平台。如果想在微信小程序中编译,只需要将<strong><span style="color: rgba(51, 102, 255, 1)">APP-PLUS</span></strong>更改为<span style="color: rgba(51, 102, 255, 1)"><strong>MP-WEIXIN</strong></span>。</h3>
<h3>二、条件编辑还支持 <strong><span style="color: rgba(51, 102, 255, 1)">|| 语法</span></strong>(不支持 &amp;&amp; 语法)。 ||表示在多个平台,比如:<strong><span style="color: rgba(51, 102, 255, 1)">// #ifdef APP-PLUS ||&nbsp;MP-WEIXIN</span></strong> 表示在APP或微信小程序平台下编译。</h3>
<h3>三、除了<strong><span style="color: rgba(51, 102, 255, 1)">#ifdef&nbsp;</span></strong>表示仅在某平台下编辑,还有<span style="color: rgba(51, 102, 255, 1)"><strong>&nbsp;Ifndef</strong> </span>表示除了某平台不编译,其它平台下都编译</h3>
<h3>四、各平台值与对应的平台如下:</h3>
<table class="MsoNormalTable" style="margin-left: -5.1pt; border-style: none" border="1" cellspacing="0">
<tbody>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: 1pt; border-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><strong><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">值</span></strong></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top-width: 1pt; border-top-color: rgba(223, 226, 229, 1); border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><strong><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">生效条件</span></strong></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">VUE3</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">HBuilderX 3.2.0+&nbsp;</span><span style="font-family: &quot;Segoe UI&quot;; color: rgba(66, 185, 131, 1); letter-spacing: 0; font-size: 9.5pt"><span style="font-family: &quot;Segoe UI&quot;">详情</span>(opens new window)</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">APP-PLUS</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">App</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">APP-PLUS-NVUE或APP-NVUE</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">App nvue</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">H5</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">H5</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-WEIXIN</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">微信小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-ALIPAY</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">支付宝小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-BAIDU</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">百度小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-TOUTIAO</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">字节跳动小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-LARK</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">飞书小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-QQ</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">QQ小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-KUAISHOU</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">快手小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-JD</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">京东小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP-360</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">360小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">MP</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt"><span style="font-family: &quot;Segoe UI&quot;">微信小程序</span>/支付宝小程序/百度小程序/字节跳动小程序/飞书小程序/QQ小程序/360小程序</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">QUICKAPP-WEBVIEW</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt"><span style="font-family: &quot;Segoe UI&quot;">快应用通用</span>(包含联盟、华为)</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">QUICKAPP-WEBVIEW-UNION</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background: rgba(246, 248, 250, 1)" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">快应用联盟</span></p>
</td>
</tr>
<tr>
<td style="padding: 6.3pt 10.5pt; border-width: initial 1pt 1pt; border-color: initial rgba(223, 226, 229, 1) rgba(223, 226, 229, 1); border-top-style: none; background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">QUICKAPP-WEBVIEW-HUAWEI</span></p>
</td>
<td style="padding: 6.3pt 10.5pt; border-left: none; border-right-width: 1pt; border-right-color: rgba(223, 226, 229, 1); border-top: none; border-bottom-width: 1pt; border-bottom-color: rgba(223, 226, 229, 1); background-image: initial; background-position: initial; background-size: initial; background-repeat: initial; background-attachment: initial; background-origin: initial; background-clip: initial" valign="center">
<p class="MsoNormal" style="margin-left: 0; text-indent: 0"><span style="font-family: &quot;Segoe UI&quot;; color: rgba(44, 62, 80, 1); letter-spacing: 0; font-size: 9.5pt">快应用华为</span></p>
</td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h3>五、pages.json 中也可以加入条件编译,比如:</h3>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> #ifdef APP-PLUS</span>
<span style="color: rgba(0, 0, 0, 1)">{
</span>"path": "pages/api/speech/speech"<span style="color: rgba(0, 0, 0, 1)">,
</span>"style"<span style="color: rgba(0, 0, 0, 1)">: {
       </span>"navigationBarTitleText" : "语音识别"<span style="color: rgba(0, 0, 0, 1)">
   }
}
</span><span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)"> #endif</span></pre>
</div>
<p>&nbsp;</p>
<h3>六、static目录编译</h3>
<p>static文件夹内存储数据文件的,默认情况下它会在APP打包时整体打包进去。</p>
<p>我们可以将不同平台下的静态文件存储在不同文件夹内<span style="color: rgba(0, 0, 255, 1)">(名称名同编译平台名的小写字母)</span>,这样打包时,就不会把微信小程序的静态文件也打包到app内。比如:</p>
<p><span style="color: rgba(0, 0, 255, 1)">/static</span><br><span style="color: rgba(0, 0, 255, 1)">/static/h5存储h5平台下的静态文件</span><br><span style="color: rgba(0, 0, 255, 1)">/static/app 存储app平台下的静态文件</span></p>
<p>&nbsp;</p>
<h3>七、整体目录条件编译</h3>
<p>如果想把各平台的页面文件更彻底的分开,也可以在uni-app项目根目录创建platforms目录,然后在下面进一步创建app-plus、mp-weixin等子目录,存放不同平台的文件。<br>platforms目录下只支持放置页面文件(即页面vue文件),如果需要对其他资源条件编译建议使用static 目录的条件编译</p><br><br>
来源:https://www.cnblogs.com/wm218/p/16664297.html
頁: [1]
查看完整版本: uni-app 条件编译