步骤:
1.装包: npm install postcss-pxtorem --save-dev
2.我的项目根目录新建vue.config.js
const autoprefixer = require('autoprefixer')const pxtorem = require('postcss-pxtorem')module.exports = { // 款式相干 css: { // 加载选项 loaderOptions: { postcss: { plugins: [ // 设置我的项目款式兼容 autoprefixer(), // px转rem的规定 pxtorem({ // 1rem 设计图中是 1rem是37.5px // 设计图宽度为37.5*10 = 375 rootValue: 37.5, propList: ['*'] }) ] } } }}
- vant-rem适配示例代码:https://github.com/youzan/vant-demo/tree/master/vant/rem