- 安装lib-flexible
npm i lib-flexible --save
- 在main.js引入lib-flexible
import 'lib-flexible/flexible'
- 安装postcss-pxtorem
npm install postcss-pxtorem -D
- 配置postcss-pxtorem
在根目录的.postcssrc.js文件中修改
此文件自动生成,若没有,手动添加
module.exports = {
"plugins": {
"autoprefixer": {},
'postcss-pxtorem': {
rootValue: 75, // 75表示750设计稿,37.5表示375设计稿
propList: ['*']
}
}
}
- 对于引入vant组件的特殊处理
- vant设计稿为375,当以750设计稿为基础设置时,需要屏蔽vant
在postcss-pxtorem对象中添加
selectorBlackList: ['van']
在postcss-pxtorem对象中添加
exclude: /web/i //忽略 web下所有文件
- 针对ipad 和 ipad pro 设备无效,针对这些设备网上找到了方法,记录下
// 在index.html中添加如下代码
<script>
/(pad|pod|iPad|iPod|iOS)/i.test(navigator.userAgent)&&(head=document.getElementsByTagName('head'),viewport=document.createElement('meta'),viewport.name='viewport',viewport.content='target-densitydpi=device-dpi, width=480px, user-scalable=no',head.length>0&&head[head.length-1].appendChild(viewport));
</script>