react以及vue 移动端适配

react

vw适配

1.下载插件

npm i postcss-loader postcss-px-to-viewport --save--dev

 2.暴露配置文件 详情看http://t.csdn.cn/YS19H

 3.配置webpack.config.js文件

[
    'postcss-px-to-viewport',//使用插件转换为css
     {
        viewportWidth: 750, // (Number) The width of the viewport. 设计稿尺寸  一般为750或者375
        viewportHeight: 1334, // (Number) The height of the viewport.
        unitPrecision: 3, // (Number) The decimal numbers to allow the REM units to grow to.
        viewportUnit: 'vw', // (String) Expected units.
        selectorBlackList: ['.ignore', '.hairlines', '.list-row-bottom-line', '.list-row-top-line'], // (Array) The selectors to ignore and leave as px.
         minPixelValue: 1, // (Number) Set the minimum pixel value to replace.
         mediaQuery: false // (Boolean) Allow px to be converted in media queries.
     }
],

rem适配

1.下载插件

npm i lib-flexible postcss-pxtorem -S

  2.暴露配置文件 详情看http://t.csdn.cn/YS19H

 3.配置webpack.config.js文件

pxtorem({
    rootValue: 37.5, //设计稿尺寸  一般为75或者37.5
    propWhiteList: [],
    minPixelValue: 2,
    exclude: /node_modules/i
}),

 4.在index.js中写入

import 'lib-flexible';

vue

vw适配

1.下载插件

npm i postcss-px-to-viewport -D

2.在项目根目录新建postcss.config.js文件

3.配置postcssc.config.js文件

module.exports = {
    plugins: {
        'postcss-px-to-viewport': {
            // 设计稿最大宽度375
            : 375,
            // 第三方UI组件单位不转vw
            exclude: /(\/|\\)(node_modules)(\/|\\)/ 
        },
    },
};

rem适配

1.下载插件

npm i lib-flexible postcss-pxtorem -D

2.在项目根目录新建postcss.config.js文件

3.配置postcssc.config.js文件

module.exports = {
    plugins: {
        'postcss-pxtorem': {
            // 根据设计稿的大小设置,一般都是375px或者750px(10)为全屏,除以10
            rootValue: 37.5,
            // 适配全部
            propList: ['*'],
        },
    },
};

4.在main.js文件中引入

import 'lib-flexible';
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值