核心代码如下
var that = this wx.getSystemInfo({ success: function (res) { this.setData({ tbodyHeight:res.windowHeight }) } })
然而在实际使用过程中发现,多个页面中每个页面调用wx.getSystemInfo获取可使用的屏幕高度的值在不同真机的出现了值不一致的问题,这也就导致了滚动视图层显示效果不佳;
解决思路是通过设置全局变量的方式;具体实现方式如下;
app.js
onLaunch: function () { wx.getSystemInfo({ success: function (res) { that.globalData.windowHeight = res.windowHeight } }) } , globalData: { windowHeight:null }
需要获取windowHeight的页面js
如index.js
const app = getApp() onReady:function(){ var tbodyHeight = app.globalData.windowHeight - 90; //90为头部固定高度 that.setData({ tbodyHeight: tbodyHeight.toFixed(0) }) }
好了,以上为我对微信小程序windowHeight每个页面值不一致的解决方案。
- 随机文章
- 热门文章
- 热评文章
- html网页 swf播放器使用代码
- UDP穿透NAT的原理与实现(UDP“打洞”原理)
- C# 非独占延时函数 非Sleep
- 永恒之蓝病毒是什么 怎么防范ONION勒索软件
- Linux下python2.7安装pip
- STM32 keil mdk启动代码发分析
- ESP8266在Eclipse下设置编译模式(有boot和无boot)
- SmartLink原理