vue配置移动端自适应

2019-11-04 17:32
67115
142523

最近在做移动H5开发,屏幕开始使用px做适配,不太好用,现在改为rem,各种百度做了自适应匹配,教程如下!勿喷、勿喷,各位觉得哪里不合适需要改进给我留言哦!

1、安装flexible

命令:cnpm install lib-flexible --save

2、安装px2rem-loader

命令:cnpm install px2rem-loader --save-dev

3、main.js中引入flexible

import 'lib-flexible'

4、配置px2rem-loader,打开build/utils.js,如下配置:

const cssLoader = {
    loader: 'css-loader',
    options: {
        sourceMap: options.sourceMap,
        importLoaders: 2
    }
};

const px2remLoader = {
    loader: 'px2rem-loader',
    options: {
        remUnit: 75
    }
};

// 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',
            publicPath: '../../'
        })
    } else {
        return ['vue-style-loader'].concat(loaders)
    }
}

5、不能在index.html的头部加 name 为 viewport 的 meta 标签(否则字体大小会固定为12px),flexible会自动为我们添加!

全部评论

2020-10-25 11:41:34.0
Looking for work <a href="http://www.dogaltedavi.org/differin-gel-3-for-wrinkles.html">adapalene cream anti aging</a> The loud one we know about - it&#039;s been going on since the Soviet Red Army wrested the northern half of the peninsula from Japanese control in 1945
2020-10-25 11:41:33.0
I'd like to send this to <a href="http://kopekciftligi.com.tr/phenazopyridine-over-counter">azo pyridium cvs</a> willinevitably lead to higher interest rates and this could resultin short-term capital movements with potential adverse effectson financially open (emerging market and developing countries).But EMDCs are in a relatively stronger position than in earlierperiods of financial distress to withstand the tremors frompossible capital flow reversals."
2020-10-25 11:33:18.0
vue配置移动端自适应 [url=http://www.g9a4jr400s5d2s9v8xpp91at0364mn0ks.org/]urocyjfeg[/url] rocyjfeg http://www.g9a4jr400s5d2s9v8xpp91at0364mn0ks.org/ <a href="http://www.g9a4jr400s5d2s9v8xpp91at0364mn0ks.org/">arocyjfeg</a>
2020-10-25 11:19:42.0
I'm a housewife <a href="http://alternativemedicinesreview.com/bystolic-cost-without-insurance.html">bystolic oral reviews satisfaction</a> She&#8217;s currently finalising her third studio album &#8216;Sucker&#8217; due out early next year.
2020-10-25 11:19:42.0
I've been cut off <a href="http://www.motorhomescotland.co.uk/asacol-side-effects.html">buy asacol 400 mg</a> The Giants finish up their three-week run against the league&rsquo;s bottom feeders by entertaining Dan Snyder&rsquo;s thoroughly but typically screwed-up outfit
2020-10-25 11:19:41.0
Have you got any ? <a href="http://dohon.co.jp/compazine-iv-uses">compazine alergic reaction</a> On days like Saturday, it&rsquo;s hard for the Yankees not to dream on the possibilities of what the big right-hander could offer their rotation
2020-10-25 11:19:40.0
I'd like to speak to someone about a mortgage <a href="http://drandrewbrown.co.uk/lasix-potassium-wasting.html">lasix 500 fiyat</a> Even if there are some long time, hard working employees that are seriously interested in helping change the company, they're going to be working within a culture that will stifle them
2020-10-25 11:19:40.0
A jiffy bag <a href="http://bodybuildingexpertzone.com/el-aciclovir-se-puede-comprar-sin-receta.html">comprar aciclovir en estados unidos</a> Quartet Pablo Zabaleta, Gael Clichy, Fernandinho and Edin Dzeko also start as Manuel Pellegrini rings the changes.
2020-10-25 10:57:47.0
Another service? <a href="http://vaccineresource.com/doxazosin-kaufen/">doxazosin generic form</a> Lawyers for the petitioners pointed to Oklahoma's botched execution last year of Clayton Lockett as proof the drug should not be administered.
2020-10-25 10:57:46.0
What line of work are you in? <a href="http://hormone-replacement-therapy.com/can-you-buy-erythromycin-ophthalmic-ointment-over-the-counter/">cost erythromycin topical</a> But this talk is not about sex education and how to handle the opposite sex - it's about how deal with law enforcement.