- 使用获取系统信息,可视化屏幕高度的解决方法,如果是ios和安卓会有点问题,需要分别减去状态栏高度和顶栏高度
- 小程序不用减去this.getClineHeight(),手机需要减去this.getClineHeight(), uni.upx2px(80) :rpx转换为px
- uni.getSystemInfo、uni.getSystemInfoSync() 获取系统信息,platform:系统类型、statusBarHeight:状态栏的高度。具体使用方法和API请访问官网:系统信息的概念 | uni-app官网
uni.getSystemInfo({
success:(res) => {
this.clentHeight = res.windowHeight - uni.upx2px(80) - this.getClineHeight()
}
})
getClineHeight(){
const res = uni.getSystemInfoSync()
const system = res.platform // ios android
if(system == 'ios'){
// ios 顶栏大概44
return 44+res.statusBarHeight;
}else if(system == 'android'){
// 安卓顶栏大概48
return 48+res.statusBarHeight;
}else {
return 0;
}
}