1)使用lib-flexible动态设置REM基准值(html标签的字体大小)
安装依赖
yarn add amfe-flexible
npm i amfe-flexible
然后在main.js
中引入加载执行该模块
import 'amfe-flexible'
最后测试:在浏览器中切换不同设备尺寸,观察html标签font-size
的变化。成功后,以后的单位直接写px即可。
![在这里插入图片描述](https://img-blog.csdnimg.cn/b8121f06ff26489b8f5d07b4512de0b0.png)
2)使用postcss-pxtorem将px
转为rem
。
安装依赖
yarn add postcss-pxtorem -D
npm i postcss-pxtorem -D