1使用postcss-pxtorem
1安装lib-flexible
npm i lib-flexible --save
2、在main.js引入lib-flexible
import 'lib-flexible/flexible'
3、安装postcss-pxtorem
npm install postcss-pxtorem -D
4、配置postcss-pxtorem
在根目录的.postcssrc.js文件中修改
此文件自动生成,若没有,手动添加
module.exports = {
"plugins": {
"autoprefixer": {},
'postcss-pxtorem': {
rootValue: 75, // 75表示750设计稿,37.5表示375设计稿
propList: ['*']
}
}
}
其他方法
vue-cli3.0 使用postcss-plugin-px2rem(推荐)和 postcss-pxtorem(postcss-px2rem)自动转换px为rem 的配置方法;