vue-移动端适配-postcss-pxtorem

  1. 安装lib-flexible

npm i lib-flexible --save
  1. 在main.js引入lib-flexible

import 'lib-flexible/flexible'
  1. 安装postcss-pxtorem

npm install postcss-pxtorem -D
  1. 配置postcss-pxtorem
    在根目录的.postcssrc.js文件中修改
    此文件自动生成,若没有,手动添加

module.exports = {
  "plugins": {
    "autoprefixer": {},
    'postcss-pxtorem': {
      rootValue: 75, // 75表示750设计稿,37.5表示375设计稿
      propList: ['*']
    }
  }
}
  1. 对于引入vant组件的特殊处理
  • vant设计稿为375,当以750设计稿为基础设置时,需要屏蔽vant

在postcss-pxtorem对象中添加
selectorBlackList: ['van']
  • 忽略文件

在postcss-pxtorem对象中添加
exclude: /web/i     //忽略 web下所有文件
  1. 针对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>



 

猜你喜欢

转载自blog.csdn.net/weixin_59519449/article/details/123881152