1.新建adaptive.js文件
function adaptive() { // 在标准 375px 适配下,1rem = 16px; var baseFontSize = 16 var baseWidth = 375 var set = function() { var clientWidth = document.documentElement.clientWidth || window.innerWidth var fz = 16 if (clientWidth != baseWidth) { fz = Math.floor(clientWidth / baseWidth * baseFontSize) } document.querySelector('html').style.fontSize = fz + 'px' } set() // 监听窗口重置事件 window.addEventListener('resize', set) } adaptive()2.在main.js中引入
// 引入自适应窗口rem
import "./assets/js/adaptive.js";
标签:Vue,适配,js,clientWidth,set,rem,var,adaptive From: https://www.cnblogs.com/sweet-potatos/p/16664301.html