首先下载flexible.js和px2rem


npm install px2rem-loader

对webpack进行配置。进入build文件夹对utils.js中的postcssLoader做如下修改


const postcssLoader = {
    loader: 'postcss-loader',
    options: {
      sourceMap: options.sourceMap,
      plugins: function () {
        return [
          require('postcss-px2rem')({remUnit: 75})
        ]
      }
    }
  }

然后在vue-loader.conf.js中的module.exports里添加


postcss: [
    require('postcss-px2rem')({remUnit: 75})
  ]

remUnit后的数字为设计稿宽度的十分之一
之后在全局引入flexible.js,在main.js加入


import '../static/js/flexible.js';

来源:https://segmentfault.com/a/1190000016112264

相关文章:

  • 2022-12-23
  • 2021-11-22
  • 2022-02-01
  • 2022-12-23
  • 2021-12-26
  • 2022-12-23
  • 2021-12-19
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-08-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案