1. 引入插件
npm i amfe-flexible
npm i postcss-pxtorem
2. 在main.js中引入
import 'amfe-flexible'
3. 在根目录下创建 postcss.config.js 文件
里面的内容如下
// postcss.config.js
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue({ file }) {
return file.indexOf('vant') !== -1 ? 37.5 : 75; // 因为vant框架是以375px的稿子为基础的,所以需要适配一下
},
//rootValue: 37.5,
propList: ['*'], // 需要转换的css属性,默认*全部
}
}
}