uniapp 运行环境 平台 机型 判断

运行环境

uni-app 可通过 process.env.NODE_ENV 判断当前环境是开发环境(运行) 还是生产环境(发行) 一般用于连接测试服务器或者生产服务器的动态切换
本地 http:// localhhost:3000
线上 http://yangyay.clud

测试服务器: development
生产服务器: production

let baseUrl = null;
if(process.env.NODE_ENV =="development"){
	// 本地服务器
	baseUrl = ' http:// localhhost:3000'
}else {
	// 线上服务器
	baseUrl = 'http://yangyay.clud'
}

平台判断

快捷键 ctrl + alt + /

  • 如果对一个盒子在不同的平台展示不同样式 可以用条件编译 解决 样式层叠
/* #ifdef H5 */

	.box {
		width: 100upx;
		height: 100upx;
	}
/* #endif */


/* #ifdef MP-WEIXIN */
	.box {
		width: 200upx;
		height: 300upx;
	}
/* #endif */
  • html
<!-- #ifdef H5 -->
			<button type="default">在h5端显示</button>
		<!-- #endif -->
		
		<!-- #ifdef MP-WEIXIN -->
			<button type="default">在微信端显示</button>
		<!-- #endif -->
  • js
// #ifdef H5
				uni.showToast({
					title:'h5显示'
				})
			// #endif
			
			// #ifdef MP-WEIXIN
				uni.showToast({
					title:'在微信端显示'
				})
			// #endif

判断机型

if (uni.getSystemInfoSync().platform == 'android') {
			
				console.log("运行在安卓手机上");

			} else if (uni.getSystemInfoSync().platform == 'ios') {

			console.log("运行在苹果手机上");
			} else {
				console.log('运行在开发工具上');
			}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值