2020-04-22  174 次浏览 评论

微信小程序动态宽高

 标签:

在项目中需要给一个view标签动态的设置高度,首先,先通过调用wx.getSystemInfo获取设备信息


  onLoad: function () {
   
    wx.getSystemInfo({  
      success: (res) => {
        this.setData({
          windowWidth: res.windowWidth * (750 / res.windowWidth),
          windowHeight: (res.windowHeight * (750 / res.windowWidth))
        })
      },
    })
    },
<view style='width:{{windowWidth}}rpx;height:{{windowHeight}}rpx;'  > </view>

给我留言

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: