uniapp 条件编译 APP 、 H5 、 小程序

一、#ifdef、#ifndef、 #endif三者的区别、

标识 作用
#ifdef 仅在某个平台上使用
#ifndef 在除了这个平台的其他平台上使用(非此平台使用)
#endif 结束条件编译

二、平台标识

标识 平台
APP-PLUS 5+App
MP 微信小程序/支付宝小程序/百度小程序/头条小程序/QQ小程序
MP-WEIXIN 微信小程序
MP-ALIPAY 支付宝小程序
MP-BAIDU 百度小程序
MP-TOUTIAO 头条小程序
MP-QQ QQ小程序
H5 H5
APP-PLUS-NVUE 5+App nvue

三、.用法

1.HTML

  1. APP端
    <!-- #ifdef APP-PLUS -->
    <view> APP端 </view>
    <!-- #endif -->
  2. H5端
     <!-- #ifdef H5 -->
     <view> H5端 </view>
     <!-- #endif -->
  3. 小程序
    <!-- #ifdef MP -->
    <view> 小程序端 </view>
    <!-- #endif -->

 2.js

  1. APP端
    /*#ifdef APP-PLUS*/  
    console.log('APP端')
    /*#endif*/
  1. H5端
     
    /*#ifdef H5*/
    console.log('H5端')
    /*#endif*/
  2. 小程序
    /*#ifdef MP*/
    console.log('微信小程序端')
    /*#endif*/

3.css

  1. APP端
    /*#ifdef APP-PLUS*/
    top:10rpx;
    /*#endif*/
  2. H5端
    /*#ifdef H5*/
    top:10rpx;
    /*#endif*/
  3. 小程序
    /*#ifdef MP*/
    top:10rpx;
    /*#endif*/ 



           

猜你喜欢

转载自blog.csdn.net/weixin_44523517/article/details/133680002