uniapp条件编译使用教学(#ifdef、#ifndef)

条件编译介绍:

条件编译是用特殊的注释作为标记,在编译时根据这些特殊的注释,将注释里面的代码编译 到不同平台。

#ifdef和#ifndef的区别:

#ifdef APP-PLUS------------只在APP显示

#ifndef APP-PLUS------------除了APP不显示,其他的都显示

javascript 复制代码
// #ifdef H5
	uni.chooseImage({
		count: 1,
		sizeType: ['original', 'compressed'],
		// sourceType: ['album'], //从相册选择
		success: function (res) {
			this.setImage({path: res.tempFilePaths,dotype:type})
			console.log(res.tempFilePaths)
		}
	});
// #endif
// #ifndef H5
	switch (type) {
		case 'face':
			uni.navigateTo({
				url: '/pages/camera/idcard/idcard?dotype=face'
			})
		    break;

		default:
			uni.navigateTo({
				url: '/pages/camera/camera'
			})
	}
// #endif
相关推荐
anyup2 小时前
uni-app 没有根组件?仅需几行代码实现全局 Toast 和 Modal
前端·架构·uni-app
2501_916007472 小时前
Python实现HTTPS爬虫的完整指南:使用requests、BeautifulSoup、Selenium和Scrapy
爬虫·python·ios·小程序·https·uni-app·iphone
AI_AGENT_DEV_AI4 小时前
原生 APP(iOS / Android)的开发与上线
uni-app
小徐_233317 小时前
Wot UI 2.3.0 发布:二维码组件来了,Open Wot 与 wot-starter 同步更新
前端·微信小程序·uni-app
skiyee20 小时前
🔥 oiyo & unibest = 又新又好的 uniapp 模板
前端·uni-app
结网的兔子3 天前
【前端开发】Web端迁移至 uni-app 及鸿蒙扩展方案对比
前端·uni-app·harmonyos
2501_915909063 天前
iOS 应用反调试技详解术 检测调试器的原理与防护实践
android·ios·小程序·https·uni-app·iphone·webview
AI多Agent协作实战派3 天前
AI多Agent协作系统实战(二十八):顶栏统一战争——从1个页面异常到31个页面全量对齐
数据库·人工智能·uni-app
00后程序员张3 天前
iOS加固技术路线全面解析:Bitcode模式、源码模式与汇编模式对比及爱加密优势
android·汇编·ios·小程序·uni-app·cocoa·iphone
2501_916008894 天前
iOS IPA文件反编译与打包操作方法,拆包分析防护和加固打包
android·macos·ios·小程序·uni-app·cocoa·iphone