vue-cli创建完项目之后安装amfe-flexible和postcss-pxtorem
cnpm install amfe-flexible@2.2.1 -S
cnpm install postcss-pxtorem@5.1.1 -D
- 在
main.js
中引用amfe-flexible
import 'amfe-flexible'
- 在
vue.config.js
中
module.exports = {
css: {
loaderOptions: {
postcss: {
plugins: [
//px自动转rem
require("autoprefixer")({
// 配置使用 autoprefixer
overrideBrowserslist: ["last 15 versions"]
}),
require("postcss-pxtorem")({
rootValue: 75, // 换算的基数(设计图750 根字体为32)
// 忽略转换正则匹配项。插件会转化所有的样式的px。比如引入了三方UI,也会被转化。目前我使用 selectorBlackList字段,来过滤
//如果个别地方不想转化px。可以简单的使用大写的 PX 或 Px 。
selectorBlackList: ["ig"],
propList: ["*"],
exclude: /node_modules/
})
]
}
}
}
}
- 查看效果
代码
浏览器效果