在App.vue文件中的mounted生命周期中加入下面一句話(huà)
mounted() {
const designW = 1440; //設(shè)計(jì)稿寬
const fontRate = 12;
setTimeout(() => {
//適配
document.getElementsByTagName("html")[0].style.fontSize =
(document.body.offsetWidth / designW) * fontRate + "px";
document.getElementsByTagName("body")[0].style.fontSize =
(document.body.offsetWidth / designW) * fontRate + "px";
}, 100);
//監(jiān)測(cè)窗口大小變化
window.addEventListener(
"onorientationchange" in window ? "orientationchange" : "resize",
function () {
document.getElementsByTagName("html")[0].style.fontSize =
(document.body.offsetWidth / designW) * fontRate + "px";
document.getElementsByTagName("body")[0].style.fontSize =
(document.body.offsetWidth / designW) * fontRate + "px";
},
false
);
}