Need to get the window width first
onLoad: function (options) {
wx.getSystemInfo({
success: (result) => {
console.log(result)
this.windowWidth = result.windowWidth
},
fail: (err) => {
console.log(err)
}
})
}
Method of converting px value to rpx value (v_px is the px value to be converted)
// px转rpx
pxToRpx(v_px) {
var onePxToRpx = 750 / this.windowWidth;
var v_rpx = v_px * onePxToRpx;
return v_rpx
},
Method of converting rpx value to px value (v_rpx is the rpx value to be converted)
// rpx转px
rpxToPx(v_rpx) {
var onePxToRpx = 750 / this.windowWidth;
var v_px = v_rpx / onePxToRpx;
return v_px
},