wx.getSystemInfo
为同步获取系统信息,有时候拿到的数据并不准确
解决方案
在onReady() 里使用getSystemInfo 异步获取
onReady(){
wx.getSystemInfo({
success:res=>{
const width = res.windowWidth;
const height = res.windowHeight;
const screenHeight = res.screenHeight
const screenWidth = res.screenWidth
const statusBarHeight = res.statusBarHeight
let radio = Math.floor(res.windowWidth / 750 * 100) / 100
app.globalData.height = (height-statusBarHeight)*(1/radio)
app.globalData.screenHeight = (screenHeight-statusBarHeight)*(1/radio)
app.globalData.width = width*(1/radio)
app.globalData.radio = radio
app.globalData.readyScreenHeight = screenHeight
app.globalData.readyScreenWidth = screenWidth
app.globalData.readyHeight = height
app.globalData.readyWidth = width
app.globalData.pixelRatio = res.pixelRatio
// console.log('ready',width,height,res.screenHeight,res.statusBarHeight,radio,app.globalData.height,app.globalData.width)
setTimeout(()=>{
this.getHeaderHeight()
},200)
}
})
},
网友评论