美文网首页
小程序 wx.getSystemInfo 获取屏幕的windo

小程序 wx.getSystemInfo 获取屏幕的windo

作者: 冰落寞成 | 来源:发表于2021-06-07 14:21 被阅读0次

    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)
          }
        })
       
      },
    

    相关文章

      网友评论

          本文标题:小程序 wx.getSystemInfo 获取屏幕的windo

          本文链接:https://www.haomeiwen.com/subject/bitjeltx.html