vue移动端适配
作者:互联网
1.安装插件
npm i lib-flexible --save // 载lib-flexible npm install px2rem-loader // 安装px2rem-loader
2.在main.js中引入lib-flexible
import 'lib-flexible/flexible'
3.在index.html中引入:移动适配meta标签
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
4.更改配置
在 build/util.js 中 按如下两更改
(1)、将px2rem-loader添加到cssLoaders中
const cssLoader = { loader: 'css-loader', options: { minimize: process.env.NODE_ENV === 'production', sourceMap: options.sourceMap } } const px2remLoader = { loader: 'px2rem-loader', options: { //一般设置75 remUnit: 37.5 // 37.5按照375设计图尺寸在设计,75安装750设计图尺寸设计 } }
(2)、在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 }) }) } // Extract CSS when that option is specified // (which is the case during production build) if (options.extract) { return ExtractTextPlugin.extract({ use: loaders, fallback: 'vue-style-loader' }) } else { return ['vue-style-loader'].concat(loaders) } }
5.重启
npm run dev
标签:vue,px2remLoader,lib,px2rem,适配,loader,flexible,移动,options 来源: https://www.cnblogs.com/dyy-dida/p/11107639.html