vue react 移动 pc端适配

React VUE PC端和移动端适配

**

踩坑!!!!!! 两种方法行内样式都不生效~

方法一 (rem)
使用lib-flexible和postcss-px2rem-exclude插件

npm install lib-flexible --save
npm  install postcss-px2rem-exclude --save 

下载完后 找到node-moduleslib-flexible文件下的flexible.js打开 修改下面代码即可

function refreshRem(){
        var width = docEl.getBoundingClientRect().width;
        if (width / dpr > 540) {
            // width = 540 * dpr; //移动端限制了宽度 所以修改宽度不固定
            width = width * dpr;
        }
        var rem = width / 10;
        docEl.style.fontSize = rem + 'px';
        flexible.rem = win.rem = rem;
    }

然后在main.js中引入

import 'lib-flexible'

如果当前项目没有postcss.config.js文件 则新建 并添加下面代码

module.exports = {
  plugins: {
    'postcss-px2rem-exclude': {
      remUnit: 192,//PC端 宽度 / 10即可 移动端 750 / 10 , 75 / 2 =37.5
      exclude: /node_modules|folder_name/i, //忽略第三方插件
    },
  },
}
最后一步注意在html根元素设置font-size
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值