1.安装包
// 作用:把px单位自动转成rem单位 (作用: 就是之前安装的vscode的插件的作用)
yarn add postcss-pxtorem -D
// 修改rem基准值的js插件 需要在打包后需要使用
// 作用: 根据设置屏幕的宽度去调整rem的值(html标签上font-size的大小)
// 它的默认计算方式是屏幕宽度的1/10,默认值是37.5
yarn add amfe-flexible
2 新建配置文件 postcss.config.js
module.exports = {
plugins: {
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
}
}
3 引入 flexible
入口文件main.js导入 amfe-flexible (动态的设置html font-size) 公式 (屏幕宽 / 10)
// 它会根据的手机尺寸来调整rem的基准值:html标签上的font-size。
import 'amfe-flexible'