px2rem-loader(Vue:移动端自适应,px自动转化)

1.下载lib-flexible

npm i lib-flexible --save

2.引入lib-flexible

import 'lib-flexible/flexible'

3.设置meta标签

4.安装px2rem-loader

npm install px2rem-loader

5.配置px2rem-loader

在build文件中找到util.js,将px2rem-loader添加到cssLoaders中,如:

复制代码

const cssLoader = {
    loader: 'css-loader',
    options: {
      minimize: process.env.NODE_ENV === 'production',
      sourceMap: options.sourceMap
    }
  }
  const px2remLoader = {
    loader: 'px2rem-loader',
    options: {
      remUnit: 75
    }
  }

// 同时,在generateLoaders方法中添加px2remLoader

function generateLoaders (loader, loaderOptions) {
  const loaders = options.usePostCSS ? [cssLoader, postcssLoader, px2remLoader] : [cssLoader, px2remLoader]
if (loader) {
  loaders.push({
  loader: loader + '-loader',
  options: Object.assign({}, loaderOptions, {
  sourceMap: options.sourceMap
  })
  })
  }

if (options.extract) {
  return ExtractTextPlugin.extract({
  use: loaders,
  fallback: 'vue-style-loader'
  })
  } else {
  return ['vue-style-loader'].concat(loaders)
  }
}

 
  

复制代码

6.重启,

npm run dev

你可能感兴趣的:(html5,html,python)