Vue,rem适配PC端

Vue,rem适配PC端,第1张

安装

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

main.js

import 'lib-flexible'

node_modules / lib-flexible / flexible.js

// 找见这个函数,把 540 改成 width
function refreshRem(){
     var width = docEl.getBoundingClientRect().width;
     if (width / dpr > 540) {
          // width = 540 * dpr;
          width = width * dpr;  // 把 540 改成 width
      }
      var rem = width / 10;
      docEl.style.fontSize = rem + 'px';
      flexible.rem = win.rem = rem;
 }

config.js

module.exports = {
    css: {
        loaderOptions: {
            css: {},
            postcss: {
                plugins: [
                    require("postcss-px2rem")({
                        remUnit: 192  // 如果设计稿是1920 这⾥就是192
                    })
                ]
            }
        }
    },
};

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/945105.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-18
下一篇2022-05-18

发表评论

登录后才能评论

评论列表(0条)

    保存