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

html中:

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中:

javascript 复制代码
// #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中:

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

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


 

#ifndef ||:

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


<!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
    <view>微信小程序和支付宝小程序环境运行</view>
<!-- #endif -->
相关推荐
说私域34 分钟前
基于定制开发开源AI智能名片与S2B2C商城小程序的旅游日志创新应用研究
人工智能·小程序·旅游
脑袋大大的1 小时前
钉钉小程序开发环境配置与前端开发指南
小程序·钉钉·企业应用开发
玩代码的菜鸟1 小时前
uniapp类似抖音视频滑动
uni-app
2301_805962934 小时前
微信小程序控制空调之接收MQTT消息
微信小程序·小程序·esp32
The_era_achievs_hero4 小时前
微信小程序121~130
微信小程序·小程序
難釋懷4 小时前
微信小程序WXSS 模板样式
微信小程序·小程序·notepad++
清颖~4 小时前
原生微信小程序研发,如何对图片进行统一管理?
微信小程序·小程序
默魔9 小时前
uniapp 微信小程序点击开始倒计时
微信小程序·小程序·uni-app
阿俊-全栈开发21 小时前
crmeb多门店对接拉卡拉支付小程序聚合收银台集成全流程详解
小程序·php·拉卡拉聚合收银台·拉卡拉三方支付
shmily ....1 天前
医疗预约系统中的录音与图片上传功能实现:Vue3+Uniapp 实战
uni-app