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 -->
相关推荐
鹧鸪云光伏与储能软件开发7 分钟前
投资储能项目能赚多少钱?小程序帮你测算
运维·数据库·小程序·光伏·光伏设计软件·光伏设计
微三云-轩30 分钟前
小程序:12亿用户的入口,企业数字化的先锋军
大数据·小程序·开源软件
低代码布道师34 分钟前
少儿舞蹈小程序(8)校区信息后台搭建
低代码·小程序
2501_9160088944 分钟前
iOS 抓包工具有哪些?全面盘点主流工具与功能对比分析
android·ios·小程序·https·uni-app·iphone·webview
2501_915921431 小时前
iOS混淆工具实战 视频流媒体类 App 的版权与播放安全保护
android·ios·小程序·https·uni-app·iphone·webview
NewChapter °1 小时前
如何通过 Gitee API 上传文件到指定仓库
前端·vue.js·gitee·uni-app
SY_FC4 小时前
uniapp阿里云验证码使用
阿里云·uni-app·notepad++
—Qeyser5 小时前
好看的背景颜色 uniapp+小程序
小程序·uni-app·uniapp·微信小游戏
2501_916008895 小时前
uni-app iOS 日志与崩溃分析全流程 多工具协作的实战指南
android·ios·小程序·https·uni-app·iphone·webview
Dark_programmer5 小时前
钉钉小程序 - - - - - 小程序内打开OA文档链接
小程序·钉钉