问题描述
解决方案:
1.安装
npm install amfe-flexible --save
npm install postcss-pxtorem@5.1.1 -D
(
postcss-pxtorem若不指定版本此处我运行会报错)
2.main.js 中 import ‘amfe-flexible’ 加载执行该模块
import 'amfe-flexible'
3.在项目根目录中创建 .postcssrc.js
文件
/**
* PostCSS 配置文件
*/
module.exports = {
// 配置要使用的 PostCSS 插件
plugins: {
// 作用:把 px 转为 rem
'postcss-pxtorem': {
rootValue ({ file }) {
return file.indexOf('vant') !== -1 ? 37.5 : 75
},
propList: ['*']
}
}
}
4.运行后就可以看到单位自动转化为rem啦