cnpm install postcss-pxtorem -D安装postcss-pxtorem
//1.创建 rem.js 文件夹 在 min.js 中引用
const baseSize = 32
function setRem() {
const scale = document.documentElement.clientWidth / 750;
document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'
}
setRem();
window.onresize = function () {
setRem();
}
//2.在项目的根目录下找到.postcssrc.js文件在文件内添加以下代码,一般750px的设计稿的根元素大小设置32.
'postcss-pxtorem': {
rootValue: 32,
propList: ['*'],
selectorBlackList: ['mint-']
}
//3.使用时直接使用设计稿上的尺寸单位使用 px