使用vue开发移动端的项目,记录下解决适配的问题,这里推荐使用两个插件:
1.npm i amfe-flexible
在main.js 中去引入 import 'amfe-flexible'
2.npm install postcss-pxtorem -D
在项目的目录下面创建postcss.config.js 文件,
module.exports = {
plugins: {
// postcss-pxtorem 插件的版本需要 >= 5.0.0
'postcss-pxtorem': {
rootValue ({ file }) {
return file.indexOf('vant') !== -1 ? 37.5 : 75
},
propList: ['*']
}
}
}
这样适配的问题就能解决了。但需要注意的的是,行内样式是px是不转化为rem的。