var style = document.body.currentStyle || document.defaultView.getComputedStyle(document.body, ""); let fs = style.fontSize.replace("px", ""); let size = fs * 3.12; var qrcode = new QRCode(this.$refs.qrCodeUrl, { text: url, // 须要转换为二维码的内容 width: size, height: size, colorDark: "#000000", colorLight: "#ffffff", });
H5端rem自适应 因为qrcode 参数传入默认px 导致不能正确居中显示二维码,解决采纳获取body.fontSize 计算出px值传入qrcode 实现不同屏幕都可居中