先安装 npm i postcss-px-to-viewport -D
然后vue.config.js中进行以下配置
module.exports = {
css:{
loaderOptions:{
css:{},
postcss:{
plugins:[
require("postcss-px-to-viewport")({
unitToConvert: 'px',
viewportWidth: 375,
unitPrecision: 5,
propList: ['*'],
viewportUnit: 'vw',
fontViewportUnit: 'vw',
selectorBlackList: ['wrap'],
minPixelValue: 1,
mediaQuery: false,
replace: true,
exclude: undefined,
include: undefined,
landscape: false,
landscapeUnit: 'vw',
landscapeWidth: 667
})
]
}
}
}
}