移动端REM适配

1. PostCss-Pxtorem 配置

yarn add -D postcss-pxtorem   // -D就是保存为开发依赖

2.创建 postcss.config.js 是PostCSS 的配置文件

module.exports = {
  plugins: {
    autoprefixer: {},
    'postcss-pxtorem': {
      // 根值:默认是37.5,来自于设计稿大小的10分之一
      rootValue: 37.5, // 根植
      propList: ['*']
    }
  }
}

3.其他设计搞尺寸

如果设计稿的尺寸不是 375,而是 750 或其他大小,可以将 rootValue 配置调整为:

module.exports = {
  plugins: {
    // postcss-pxtorem 插件的版本需要 >= 5.0.0
    'postcss-pxtorem': {
      rootValue({ file }) {
        return file.indexOf('vant') !== -1 ? 37.5 : 75;
      },
      propList: ['*']
    }
  }
}

注意:

如果报错.可能原因是 postcss-pxtorem 版本过高

建议下载 postcss-pxtorem @5.1.1版本

4. amfe-flexible 的方法就是把一行分为十份.每分大小除以十 根据设备匹配

npm i amfe-flexible
yarn add amfe-flexible 

man.js中
// 动态加载设置 REM 基准值
import 'amfe-flexible/index'

最后重新启动项目.查看是否转换为REM了.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值