1.适配方案
amfe-flexible 和 postcss-pxtorem
amfe-flexible 是配置可伸缩布局方案,主要是将 1rem 设为 viewWidth/10。
postcss-pxtorem是postcss的插件,用于将像素单元生成rem单位。
2.使用和配置
1.amfe-flexible
npm install amfe-flexible --save
在main.js使用
import 'amfe-flexible';
2.postcss-pxtorem
npm i postcss-pxtorem@5.1.1 --save //这个要装5.1.1版本的
新建postcss.config.js文件
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
}
}
rootValue:转换根元素的基准值 一般是设计稿的十分之一
propList:需要转换的属性,*表示所有属性都转换
配置完毕,重新启动服务。审查元素样式查看是否已将 px 转换为 rem