0
点赞
收藏
分享

微信扫一扫

uniapp兼容不同小程序环境写法

拾杨梅记 2024-10-31 阅读 18

html中:

<!-- #ifdef MP-WEIXIN -->
    <view>只在微信小程序环境运行</view>
<!-- #endif -->

<!-- #ifdef MP-ALIPAY -->
   <view>只在支付宝小程序环境运行</view>
<!-- #endif -->

<!-- #ifdef MP-QQ -->
   <view>只在QQ小程序环境运行</view>
<!-- #endif -->

<!-- #ifdef H5 -->
    <view>只在h5环境运行</view>
<!-- #endif -->

<!-- #ifdef APP-NVUE -->
   <view>只在支付宝小程序环境运行</view>
<!-- #endif -->

js中:

// #ifdef MP-WEIXIN
    console.log("只在微信小程序环境运行")
// #endif

// #ifdef MP-ALIPAY
    console.log("只在支付宝小程序环境运行")
// #endif

// #ifdef MP-QQ
    console.log("只在QQ小程序环境运行")
// #endif

// #ifdef H5
    console.log("只在h5环境运行")
// #endif

// #ifdef APP-NVUE
    console.log("只在APP-NVUE环境运行")
// #endif

css中:

/* #ifdef MP-WEIXIN */
    //只在微信小程序环境运行
/* #endif */
 
/* #ifdef MP-ALIPAY */
    //只在支付宝小程序环境运行
/* #endif */
 
/* #ifdef MP-QQ */
    //只在qq小程序环境运行
/* #endif */

/* #ifdef APP-NVUE */
    //只在APP-NVUE环境运行
/* #endif */


 

#ifndef   ||:

<!-- #ifndef MP-WEIXIN -->
    <view>只要不是微信小程序都运行</view>
<!-- #endif -->


<!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
    <view>微信小程序和支付宝小程序环境运行</view>
<!-- #endif -->
举报

相关推荐

0 条评论