小陆同学

python 中文名:蟒蛇,设计者:Guido van Rossum

导航

vue项目移动端适配

下载lib-flexible

npm i lib-flexible --save

在main.js中引入lib-flexible

import 'lib-flexible/flexible'

查看index.js有没有添加meta标签

<meta name="viewport" content="width=device-width,initial-scale=1.0">
//注意这两个的区别,建议添加下面的meta,反正点击输入框,页面自动缩放
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">

 

安装px2rem-loader

npm install 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: {
    //一般设置75
    remUnit: 35
    }
}

同时,在generateLoaders方法中添加px2remLoader

// generate loader string to be used with extract text plugin

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)
}
}

npm run dev重新运行
原文链接:https://blog.csdn.net/huangxiaoguo1/article/details/80284484

posted on 2022-03-05 22:02  小陆同学  阅读(129)  评论(0编辑  收藏  举报