- Install lib-flexible
npm i lib-flexible --save
- Introduce lib-flexible in main.js
import 'lib-flexible/flexible'
- Install postcss-pxtorem
npm install postcss-pxtorem -D
- 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: ['*']
}
}
}
- 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下所有文件
- 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>