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 -->
相关推荐
前端(从入门到入土)8 小时前
uniapp加载json动画
uni-app·json
peachSoda713 小时前
uniapp小程序生成海报/图片并保存分享
小程序·uni-app
奔跑吧邓邓子14 小时前
使用 Spring Boot 和 Uniapp 搭建 NFC 读取系统
spring boot·uni-app·nfc数据读取
说私域15 小时前
社交电商引流策略中的让利行为及其影响——基于开源AI智能名片、链动2+1模式与S2B2C商城小程序的分析
人工智能·小程序·开源·产品运营·零售
罗政15 小时前
AI小程序+SpringAI+管理后台+源码+支持动态添加大模型+支持动态添加AI应用
人工智能·小程序
社会底层无业大学生16 小时前
微信小程序跳2
微信小程序·小程序·notepad++
说私域20 小时前
开源AI大模型AI智能名片S2B2C商城小程序:科技浪潮下的商业新引擎
人工智能·小程序·开源·产品运营·零售
zru_960220 小时前
微信小程序事件详解
微信小程序·小程序
sunly_1 天前
uniapp:微信小程序,一键获取手机号
微信小程序·小程序·uni-app