1、防抖
npm install lodash.debounce -save-dev
2、在main.js写上如下代码
const windowResize = function() {console.log("resize");var html = document.getElementsByTagName('html')[0];/*取到屏幕的宽度*/var width = window.innerWidth;/* 640 100 320 50 */var fontSize = 100 / 750 * width;/*设置fontsize*/html.style.fontSize = fontSize + 'px';window.onresize = function() {var html = document.getElementsByTagName('html')[0];/*取到屏幕的宽度*/var width = window.innerWidth;/* 640 100 320 50 */var fontSize = 100 / 750 * width;/*设置fontsize*/html.style.fontSize = fontSize + 'px';}
};windowResize();
window.onresize = debounce(windowResize, 200);