当前位置:网站首页>px2rem-loader将px转化为rem,适配移动端vant-UI等框架
px2rem-loader将px转化为rem,适配移动端vant-UI等框架
2022-07-26 10:38:00 【songywaa】
简单描述
最近尝试了几个移动端的ui框架,发现vant-ui还不错;
但是有个问题,就是vant-ui单位是px,使用时需要我们自己去转换为rem;
具体实现方法
1.下载lib-flexible
使用的是vue-cli+webpack,通过npm来安装的
npm i lib-flexible --save
2.引入lib-flexible
在main.js中引入lib-flexible
import 'lib-flexible/flexible'
3.设置meta标签
通过meta标签,设置设备宽度以及缩放比例
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
4.安装px2rem-loader
npm install px2rem-loader
5.配置px2rem-loader
这里是重要的一步~~
在build文件中找到util.js,将px2rem-loader添加到cssLoaders中,如:
const px2remLoader = {
loader: 'px2rem-loader',
options: {
remUnit: 75 // 这里设置html根字体,vant-UI的官方根字体大小是37.5
}
}
同时,在generateLoaders方法中添加px2remLoader
function generateLoaders (loader, loaderOptions) {
const loaders = options.usePostCSS ? [cssLoader, postcssLoader, px2remLoader] : [cssLoader, px2remLoader]
...
...
...
}
6.当配置完之后,只需要重启下服务,就自动转化为rem了
npm run dev
重启之后,查看浏览器中的单位已经变成rem了;
边栏推荐
- C语言鹏哥20210812C语言函数
- [leetcode daily question 2021/8/30]528. Choose randomly by weight [medium]
- Mlx90640 infrared thermal imager temperature sensor module development notes (VI) pseudo color coding of infrared images
- 第5期:大学生入职必备技能之二
- Tradingview tutorial
- 7-25 0-1背包 (50分)
- 抽象工厂及其改进示例
- 粽子大战 —— 猜猜谁能赢
- C language calculation date interval days
- C language callback function
猜你喜欢
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)
QRcode二维码(C语言)遇到的问题
putty的使用教程
[leetcode daily question 2021/2/18] [detailed explanation] minimum number of turns of 995. K continuous bits
Introduction to data analysis | kaggle Titanic mission
Navicat15 MySQL (centos7) connected to local virtual machine
Okaleido生态核心权益OKA,尽在聚变Mining模式
控制随机抽中几率 [ C# | Random ]
第8期:云原生—— 大学生职场小白该如何学
【dectectron2】跟着官方demo一起做
随机推荐
Oracle创建索引
GIS方法类期刊和论文的综述(Introduction)怎么写?
QRcode二维码(C语言)遇到的问题
链式方法调用的事务问题剖析
.net5wtm (asp.net core) PgSQL unpacking operation
[machine learning notes] [style transfer] deeplearning ai course4 4th week programming(tensorflow2)
Simple use of json-c Library -- converting JSON files to struct
2021-08-12函数递归_和鹏哥学习C语言
sigmod 函数与softmax 函数对比
Redis特殊数据类型使用场景
[paper after dinner] deep mining external perfect data for chestx ray disease screening
【dectectron2】跟着官方demo一起做
[leetcode daily question 2021/8/31] 1109. Flight reservation statistics [medium] differential array
比较器(Comparable与Comparator接口)
[machine learning notes] [face recognition] deeplearning ai course4 4th week programming
Phase 4: one of College Students' vocational skills preparation in advance
[leetcode daily question 2021/2/14]765. Lovers hold hands
[notes on machine learning] [building a cyclic neural network and its application] deeplearning ai course5 1st week programming(keras)
Centos8 (liunx) deploying WTM (asp.net 5) using PgSQL
扫雷pro版2021-08-19