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
相关推荐
2501_915106324 小时前
iOS数据采集技术详解:从性能监控到崩溃分析的全链路实践
android·ios·小程序·https·uni-app·iphone·webview
我爱写代码i19 小时前
AI对话绘画数字人源码 - uniapp前端
前端·人工智能·uni-app
ModyQyW19 小时前
vite-plugin-uni-pages 更新了什么
前端·uni-app
2501_915918411 天前
Flutter项目配置iOS混淆的详细步骤与工具推荐
android·flutter·ios·小程序·uni-app·cocoa·iphone
梦曦i1 天前
create-uni-app v1.2.0:交互体验优化
前端·uni-app
lhldsg2 天前
智慧场馆解决方案小程序开发实战:从架构设计到部署指南
java·小程序·uni-app
skiyee2 天前
🚀 用 17 行代码给 UniApp 加上全局登录拦截
前端·uni-app
Mark108592 天前
【踩坑】Uni-app微信小程序自定义组件在 Flex 布局中未铺满整行
微信小程序·小程序·uni-app
梦曦i2 天前
create-uni-app v1.1.0:结构化生成,工程骨架更规范
前端·uni-app
2501_916007473 天前
Flutter与游戏App加固避坑指南:如何为混合开发与高交互应用选对安全方案?
安全·flutter·游戏·ios·小程序·uni-app·iphone