最近在写移动端的项目,简单记录一下适配问题。
使用插件:参考(Vant 4 - A lightweight, customizable Vue UI library for mobile web apps.)
1.postcss-pxtorem
2.lib-flexible/flexible
由于UI图宽度不一致,所以另外创建postcss.config.cjs文件进行配置
// postcss.config.js
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue({ file }) {
return file.indexOf('vant') !== -1 ? 37.5 : 39; // 因为vant框架是以375px的稿子为基础的,所以需要适配一下
},
propList: ['*'], // 需要转换的css属性,默认*全部
}
}
}