npm install lib-flexible 安裝:
在main.js引入中:import 'lib-flexible/flexible.js'
1.1、npm install postcss-pxtorem 或者 yarn add postcss-pxtorem:
在package.json內,在postcss內添加:
"postcss": {
"plugins": {
"autoprefixer": {},
"postcss-pxtorem": {
"rootValue": 75, // 設計稿寬度的1/10,(JSON文件中不加註釋,此行註釋及下行註釋均刪除)
"propList":["*"] // 需要做轉化處理的屬性,如`hight`、`width`、`margin`等,`*`表示全部
}
}
},
1.2、或者使用 npm install --save-dev postcss-loader postcss-px2rem
在vue.config.js中配置
module.exports = {
css: {
loaderOptions: {
css: {
// options here will be passed to css-loader
},
postcss: {
// options here will be passed to postcss-loader
plugins: [require('postcss-px2rem')({
remUnit: 75
})]
}
}
}
}