使用安卓机器,华为nova5i进行真机调试,在跳转页面时onload()获取可使用窗口高度(windowHeight),有时候数值会不一致。
代码如下:
let systemInfo = wx.getSystemInfoSync()
this.setData({
aaa:systemInfo.windowHeight,
bbb: systemInfo.windowHeight - 80,
})
console.log("赋值啦")
console.log(this.data.aaa)
console.log(this.data.bbb)
console截图如下:

页面是否有自定义 tabbar/自定义导航栏?
存在问题
安卓设备下获取
windowHeight不能准确得到对应的高度,总是拿到屏幕高度原因
1. 同步接口
wx.getSystemInfoSync并不同步(猜测)wx.getSystemInfoSync只是在页面初始化时提前计算。所以对于windowHeight这种需要进行功能判断的属性,应该使用异步接口,实时获取2. wx.getSystemInfo 调用的时机不当
上面讲了
windowHeight的定义,所以这个值取决于tabbar是否存在为了保证
tabbar显示后再进行取值,建议在生命周期的onReady钩子中调用接口wx.getSystemInfo最终方案
wx.getSystemInfoonReady中调用代码
onReady() { wx.getSystemInfo({ success({windowHeight}) { // todo } }); }