vue rem自适应布局如何实现?
作者:互联网
找到main.js,最下方加上如下代码即可实现(页面中写代码时把设计稿除以100即可,例如:100px就是1rem):
;(function(win) {
var tid;
function refreshRem() {
let designSize = 1920; // 设计图尺寸,如果是移动端改为750
let html = document.documentElement;
let wW = html.clientWidth;// 窗口宽度
let rem = wW * 100 / designSize;
document.documentElement.style.fontSize = rem + 'px';
}
win.addEventListener('resize', function() {
clearTimeout(tid);
tid = setTimeout(refreshRem, 300);
}, false);
win.addEventListener('pageshow', function(e) {
if (e.persisted) {
clearTimeout(tid);
tid = setTimeout(refreshRem, 300);
}
}, false);
refreshRem();
})(window);
标签:function,vue,win,布局,let,rem,tid,refreshRem 来源: https://blog.csdn.net/qq_43069664/article/details/120495768