在libs的setRem.js中:
let html = document.querySelector("html");
function setRem() {
let ui_w = 375;
let cl_w = document.documentElement.clientWidth || document.body.clientWidth;
cl_w > 750 ? cl_w = 375 : "";
html.style.fontSize = (cl_w / ui_w) * 10 + "px";
};
window.addEventListener('resize', setRem);
window.addEventListener("load", setRem);
在main.js中:
// 引入setRem
import "./libs/setRem.js";
在App.vue中:
html, body {
font-size: 10px;
max-width: 375px;
margin: 0 auto;
position: relative;
}