(1)安裝postcss-pxtorem
npm install postcss-pxtorem -D
(2) 安裝 postcss、 postcss-loader、amfe-flexible
npm install postcss postcss-loader amfe-flexible --save
(3) 在main.js中引入amfe-flexible
import 'amfe-flexible'
(4) 配置,創(chuàng)建postcss.config.js文件
module.exports = {
plugins: {
"postcss-pxtorem": {
"rootValue":75, // 設(shè)計(jì)稿寬度的1/10
"propList": ["*"]// 需要做轉(zhuǎn)化處理的屬性,如`hight`、`width`、`margin`等,`*`表示全部
}
}
}
(5)完成。重啟項(xiàng)目。