随笔 - 633,  文章 - 0,  评论 - 13,  阅读 - 48万
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

1.npm install lib-flexible

2.然后在main里引入组件 :    import 'lib-flexible/flexible.js'

3.npm install postcss-plugin-px2rem --save

4.然后在vue.config.js(在项目根目录下,没有就新建一个vue.config.js)里配置内容:

复制代码
module.exports = {
    css: {
        loaderOptions: {
            css: {
                // options here will be passed to css-loader
            },
            postcss: {
                plugins: [
                    require("postcss-plugin-px2rem")({
                        rootValue: 37.5, //换算基数,
                        // unitPrecision: 5, //允许REM单位增长到的十进制数字。
                        //propWhiteList: [],  //默认值是一个空数组,这意味着禁用白名单并启用所有属性。
                        propBlackList: ["border"], //黑名单
                        exclude: /(node_module)/, //默认false,可以(reg)利用正则表达式排除某些文件夹的方法。默认值为false,即该项目中所有的px均会被转换为rem
                        //(以上exclude配置,如/node_modules|pc/i  排除node_modules文件夹以及所有名为pc的文件夹下的,所有文件的px转换)
                        selectorBlackList: ['van-', 'el-'], //要忽略并保留为px的选择器。此处举例:van-为vant-UI的前缀,el-为element-UI的前缀
                        // ignoreIdentifier: false,  //(boolean/string)忽略单个属性的方法,启用ignoreidentifier后,replace将自动设置为true。
                        // replace: true, // (布尔值)替换包含REM的规则,而不是添加回退。
                        mediaQuery: false, //(布尔值)允许在媒体查询中转换px。
                        minPixelValue: 2, //设置要替换的最小像素值(2px会被转rem)。 默认 0
                    }),
                ]

            }
        }
    }
}
复制代码

5.然后在index.html添加内容:

    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0,shrink-to-fit=no,user-scalable=no">
   

6.重启vue

 
posted on   大话人生  阅读(6247)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
点击右上角即可分享
微信分享提示