第一步在创建好的项目中安装 amfe-flexible postcss-pxtorem
yarn add postcss-pxtorem@5.1.1
yarn add amfe-flexible
postcss-pxtorem 安装5.1.1 版本 因为最新版本打包时可能会出错!
第二步在main.js中引入amfe-flexible
第三步在vue.config.js中配置css
css: {
loaderOptions: {
postcss: {
plugins: [
require('postcss-pxtorem')({ // 把px单位换算成rem单位
rootValue: 132, // 换算的基数(设计图750的根字体为75)
propList: ['*']
})
]
}
},
},
完成后需要重新编译才能生效!!
本文暂时没有评论,来添加一个吧(●'◡'●)