实现rem适配
1) 下载依赖包
yarn add amfe-flexible postcss postcss-pxtorem@5.1.1
说明:
amfe-flexible: 将页面宽度
postcss-pxtorem不能下载最新版本, 与postcss不适配
2) 配置postcss-pxtorem
postcss.config.js
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5, // 设计图页面宽度为375, 划分成10份, 指定1rem=37.5
propList: ['*'],
},
},
};
3) 在入口js中加载amfe-flexible
main.js
import 'amfe-flexible'