vue配置移动端自适应

2019-11-04 17:32
67108
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 10:57:42.0
Sorry, you must have the wrong number <a href="http://spiritadventures.co.uk/where-to-buy-alavert-d-12">allergy under tongue alavert alternative loratadine</a> The FCC on Friday voted unanimously to open a so-called"notice of inquiry" into what it and the industry can do to turna new swath of very high-frequency airwaves, previously deemedunusable for mobile networks, into mobile-friendly frequencies.
2020-10-25 10:57:41.0
Is this a temporary or permanent position? <a href="http://galopturk.com/?amoxicillin-500mg-2-times-a-day-for-tooth-infection">antibiotics amoxicillin in pregnancy</a> Dorries thinks this reaction will spread to other women too, meaning that the actions of her stalker could stop women from progressing into high-profile jobs and shattering glass ceilings.
2020-10-25 10:57:40.0
Withdraw cash <a href="http://drgeorgelikes.com/bisoprolol-2-5mg-kaufen">bisoprolol 10 kaufen</a> Dre headphones, "There was literally nothing like it before in the headphone market."
2020-10-25 10:35:48.0
We need someone with qualifications <a href="http://alternativemedicinesreview.com/cataflam-for-sale.html">cataflam jarabe dosis para adultos</a> A growing number of children are using prescription puberty blockers so that they can stop unwanted changes in their bodies like breasts or facial hair.
2020-10-25 10:35:46.0
I support Manchester United <a href="http://www.mitoloji.org/zydena-vs-viagra.html">preço de zydena 100 mg</a> It&#039;s thought that this serum may contain particles that could neutralise the virus
2020-10-25 10:35:46.0
International directory enquiries <a href="http://kbtlund.se/cheapest-family-vacations-in-california">frumil online</a> In short, this new innovation from Estonia, while perhaps a little gimmicky, is the harbinger of what&rsquo;s coming on a much larger scale
2020-10-25 10:35:45.0
Hold the line, please <a href="http://homelinesport.co.il/product.php?prod=curvimax-information">vimax video</a> The minutes of the central bank's last policymaking meeting showed a growing rift between so-called hawks, who worry rising inflation could hurt the economy, and doves, who want to continue the unprecedented easy money policies until the job market is stronger.
2020-10-25 10:35:45.0
US dollars <a href="http://vaccineresource.com/buy-unique-hoodia-australia/">where to buy hoodia in australia</a> In addition to their limited-edition watches, the "ace" golfers are also awarded membership of the exclusive BOSS Watches H1 Club, which offers its members access to exclusive benefits and merchandise.
2020-10-25 10:13:22.0
I work here <a href="http://www.panjerehweekly.ir/vpxl-funciona/does-cbd-oil-working-for-anxiety-in-dogs-not-pregnant">vxl-3s blinking red</a> The UN Children's Fund launched a program to allow Syrian families in Jordan to buy winter clothes for their children, while Save the Children and the U.N
2020-10-25 10:13:22.0
Can I call you back? <a href="http://vaccineresource.com/clozapine-vs-clozaril/">buying clozaril</a> The borders, combatants, allegiances, and military objectives in the Syrian war are too fluid to conform to our usual expectations