方式一:getSystemInfo:需要在success方法中取值
wx.getSystemInfo({
success:function(res) {
console.log(res.windowWidth, '宽')
console.log(res.windowHeight, '长')
}
})
方式二:getSystemInfoSync:可以直接".windowWidth"取值
console.log(wx.getSystemInfoSync().windowWidth, '宽')
console.log(wx.getSystemInfoSync().windowHeight, '长')
1、官方上规定屏幕宽度为20rem,规定屏幕宽为750rpx,则1rem=750/20rpx。
即:不论哪个型号的手机,屏幕宽度都是750rpx
2、微信小程序rpx,px,rem单位换算规则
屏幕实际宽度为:wx.getSystemInfoSync().windowWidth px
对应的屏幕宽度为:750rpx
即:1px = (750 / wx.getSystemInfoSync().windowWidth) rpx
1rpx = (wx.getSystemInfoSync().windowWidth / 750) px
1rem = (wx.getSystemInfoSync().windowWidth / 20) px