vue-mobile terminal adaptation-postcss-pxtorem

  1. Install lib-flexible

npm i lib-flexible --save
  1. Introduce lib-flexible in main.js

import 'lib-flexible/flexible'
  1. Install postcss-pxtorem

npm install postcss-pxtorem -D
  1. Configure postcss-pxtorem
    and modify it in the .postcssrc.js file in the root directory.
    This file is automatically generated. If not, add it manually

module.exports = {
  "plugins": {
    "autoprefixer": {},
    'postcss-pxtorem': {
      rootValue: 75, // 75表示750设计稿,37.5表示375设计稿
      propList: ['*']
    }
  }
}
  1. Special handling for introducing vant components
  • The vant design draft is 375. When setting based on the 750 design draft, you need to shield the vant

在postcss-pxtorem对象中添加
selectorBlackList: ['van']
  • ignore files

在postcss-pxtorem对象中添加
exclude: /web/i     //忽略 web下所有文件
  1. It is invalid for ipad and ipad pro devices. For these devices, I found a method online and recorded it.

// 在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>



 

Guess you like

Origin blog.csdn.net/weixin_59519449/article/details/123881152