1、安装
npm i lib-flexible
2、然后在 main.js 中加载执行该模块
import ‘lib-flexible’
3.npm install postcss-pxtorem
4.然后在项目根目录中创建 .postcssrc.js 文件
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 80,
propList: ['*']
}
}
}
5.在flexible.js文件中修改refreshRem()
function refreshRem(){
var width = docEl.getBoundingClientRect().width;
if (width <= 1336) {
width = 1336;
}
var rem = width / 24; //1920的设计稿平分24份 1rem=80px
docEl.style.fontSize = rem + 'px';
flexible.rem = win.rem = rem;
}