1.amfe-flexible是配置可伸缩布局方案,主要是将1rem设为viewWidth/10。
2.postcss-pxtorem是postcss的插件,用于将像素单元生成rem单位。
3.安装amfe-flexible和postcss-pxtorem:
npm install amfe-flexible -S
npm install postcss-pxtorem -S
npm install amfe-flexible -S
npm install postcss-pxtorem -S
在main.js引入amfe-flexible
import 'amfe-flexible';
在vue.config.js添加配置postcss-pxtorem;(注意:可在vue.config.js、.postcssrc.js、postcss.config.js其中之一配置,权重从左到右降低,没有则新建文件,只需要设置其中一个即可)
module.exports = {
css:{
loaderOptions:{
postcss:{
plugins:{
require('postcss-pxtorem')({
rootValue:192, // ui设计图/10,可以根据项目的UI图定义
propList:['*']
})