微信小程序自定义导航栏高度获取出错windowHeight值不一致
核心代码如下
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每个页面值不一致的解决方案。
- 随机文章
- 热门文章
- 热评文章
- PHP实现表单内容写入txt文件的代码
- C#中的MessageBox消息对话框
- C#修改图片分辨率
- 物联网 WIFI 一键配置原理(smartconfig) ESP8266/QCA4004
- c# 全局鼠标事件
- C#全局监听Windows键盘事件
- USB2.0协议标准描述符详解
- ESP8266发送HTTP请求GET请求POST请求