方法一:需要在index.html中写入监听事件
【注】:获取html、body是有特定的方法的
<script>
let tid = null;
function resizeWindow() {
const docEl = document.documentElement;
//当前页面的长度
const HtmlDom = docEl.getBoundingClientRect().width;
//设置rem
docEl.style.fontSize = HtmlDom / 192 + "px";
}
window.addEventListener("resize", () => {
this.clearTimeout(tid);
tid = this.setTimeout(resizeWindow, 300);
});
resizeWindow();
</script>