vue使用flexible和px2rem实现移动端适配

首先下载flexible.js和px2remcss

npm install px2rem-loader

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

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

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

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

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

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

来源:http://www.javashuo.com/article/p-kckafhxs-dr.htmlnpm

相关文章
相关标签/搜索