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 -->
相关推荐
腾马科技1 小时前
新版saas餐饮外卖小程序源码/微信/支付宝/抖音/扫码点餐/DIY装修/美团代付/全开源
微信小程序·小程序·点餐小程序
用户904706683575 小时前
uniapp Vue3版本,用pinia存储持久化插件pinia-plugin-persistedstate对微信小程序的配置
前端·uni-app
郑叔敲代码6 小时前
帝国cms 微信小程序的登录逻辑
微信小程序·小程序·notepad++
细节控菜鸡6 小时前
【2025最新】uniapp 中基于 request 封装实现多文件上传完整指南
uni-app
fakaifa6 小时前
【全开源】企业微信SCRM社群营销高级版系统+uniapp前端
uni-app·开源·企业微信·scrm·源码下载·企业微信scrm
棋子一名9 小时前
跑马灯组件 Vue2/Vue3/uni-app/微信小程序
微信小程序·小程序·uni-app·vue·js
无衣 秦风10 小时前
vue3+hubuilderX开发微信小程序使用elliptic生成ECDH密钥对遇到的问题
微信小程序·小程序
游戏开发爱好者810 小时前
BShare HTTPS 集成与排查实战,从 SDK 接入到 iOS 真机调试(bshare https、签名、回调、抓包)
android·ios·小程序·https·uni-app·iphone·webview
2501_9160088910 小时前
iOS 26 系统流畅度实战指南|流畅体验检测|滑动顺畅对比
android·macos·ios·小程序·uni-app·cocoa·iphone
流***陌11 小时前
陪诊就医小程序中健康档案的精细化管理设计方案
小程序