2022-11-21 21:45:44
vue项目使用postcss-pxtorem
1、安装 postcss-pxtorem依赖
npm install postcss-pxtorem
2、src目录下新建rem.js文件 内容如下:
const baseSize = 37.5
function setRem () {
const scale = document.documentElement.clientWidth / 375
document.documentElement.style.fontSize = (baseSize * Math.min(scale, 2)) + 'px'
}
setRem()
window.onresize = function () {
setRem()
}
3、main.js引入rem文件
import './rem'
4、根目录下新建 postcss.config.js文件 内容如下:
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*'],
},
},
};
5、重启服务
最后生成于 2023-08-15 14:32:56
热门推荐: