vue3实现本地开发使用的px转换成vw,px转换成rem方法整理

前言:

        项目中如果想本地开发使用px,但是界面上线以后界面是自适应的效果,可以有多种方式来实现效果。

一、px转成vw

1、安装,安装成功后,node_modules 会新增这两个插件包

npm i postcss-px-to-viewport-8-plugin

2、新增  postcss.config.js 文件

module.exports = {plugins: {tailwindcss: {},autoprefixer: {},"postcss-px-to-viewport-8-plugin": {// (String) 需要转换的单位,默认为"px"            unitToConvert: 'px',// (Number) 设计稿的视口宽度            viewportWidth: 1920,// (Number) 单位转换后保留的精度            unitPrecision: 5,/**             * (Array) 能转化为vw的属性列表             * 传入特定的CSS属性;             * 可以传入通配符""去匹配所有属性,例如:[''];             * 在属性的前或后添加"*",可以匹配特定的属性. (例如['position'] 会匹配 background-position-y)             * 在特定属性前加 "!",将不转换该属性的单位 . 例如: ['*', '!letter-spacing'],将不转换letter-spacing             * "!" 和 ""可以组合使用, 例如: ['', '!font*'],将不转换font-size以及font-weight等属性             */propList: ['*'],// (String) 希望使用的视口单位            viewportUnit: 'vw',// (String) 字体使用的视口单位            fontViewportUnit: 'vw',/**             * (Array) 需要忽略的CSS选择器,不会转为视口单位,使用原有的px等单位。             * 如果传入的值为字符串的话,只要选择器中含有传入值就会被匹配:例如 selectorBlackList 为 ['body'] 的话, 那么 .body-class 就会被忽略             * 如果传入的值为正则表达式的话,那么就会依据CSS选择器是否匹配该正则:例如 selectorBlackList 为 [/^body$/] , 那么 body 会被忽略,而 .body 不会             */selectorBlackList: [],// (Number) 设置最小的转换数值,如果为1的话,只有大于1的值会被转换            minPixelValue: 1,// (Boolean) 媒体查询里的单位是否需要转换单位            mediaQuery: false,// (Boolean) 是否直接更换属性值,而不添加备用属性            replace: true,/**             * (Array or Regexp) 忽略某些文件夹下的文件或特定文件,例如 'node_modules' 下的文件             * 如果值是一个正则表达式,那么匹配这个正则的文件会被忽略             * 如果传入的值是一个数组,那么数组里的值必须为正则             */exclude: undefined,/**             * (Array or Regexp) 如果设置了include,那将只有匹配到的文件才会被转换,例如只转换 'src/mobile' 下的文件 (include: /\/src\/mobile\//)             * 如果值是一个正则表达式,将包含匹配的文件,否则将排除该文件             * 如果传入的值是一个数组,那么数组里的值必须为正则             */include: undefined,// (Boolean) 是否添加根据 landscapeWidth 生成的媒体查询条件 @media (orientation: landscape)            landscape: false,// (String) 横屏时使用的单位            landscapeUnit: 'vw',// (Number) 横屏时使用的视口宽度            landscapeWidth: 1920},},
}

二、px转成rem

1、安装

npm i postcss    postcss-preset-env    postcss-pxtorem

2、 新增  postcss.config.js 文件

 module.exports = {plugins: {'postcss-preset-env': {autoprefixer: true,},'postcss-pxtorem': {rootValue: 16, // 基准字体大小unitPrecision: 5, // 转换后的rem保留小数点位数propList: ['*'], // 要转换的属性,默认转换所有属性},},};

3、其他px->rem的方法:使用插件lib-flexible

vue-cli3.0搭建移动端项目的适配问题以及解决第三方组件样式受影响的问题_npm 移动端预docx ppx-CSDN博客文章浏览阅读896次。前言: 我们之前使用的解决移动端适配常用的方法是媒体查询+rem,em,这种适合小的项目,而且每次rem值计算也太麻烦了点,这里列出现在常用的另一种方法就是:lib-flexible和 postcss-px2rem-exclude来完美的解决适配问题。步骤一:安装lib-flexible - 适配插件,自动添加头部 meta1 安装npm install lib-..._npm 移动端预docx ppxhttps://blog.csdn.net/qq_41619796/article/details/102778379?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170347335516800213088403%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=170347335516800213088403&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~rank_v31_ecpm-2-102778379-null-null.nonecase&utm_term=rem&spm=1018.2226.3001.4450

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/543727.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

airplay2协议是什么_什么是AirPlay?

airplay2协议是什么AirPlay (AirPlay) AirPlay is released by Apple in the year 2004. It allows the easy exchange of audios without the use of any wired technique between the two devices. It was previously termed as AirTunes and later got its name changed to …

微信支付开发(5) 订单查询

本文介绍微信支付中订单查询功能的实现。 作者:方倍工作室 地址:http://www.cnblogs.com/txw1958/p/wxpay-order-query.html 一、订单查询 因为某一方技术的原因,可能导致商户在预期时间内都收不到最终支付通知,此时商户可以通过该…

ruby 执行函数_Ruby at()函数

ruby 执行函数Ruby中的at()函数 (at() function in Ruby) If you are working with arrays in Ruby, sometimes you may need to find the element at a particular index. For meeting the purpose, we have got at() function in Ruby which is already defined in Rubys lib…

python饼形图_Python | 饼形图

python饼形图A pie plot or a pie chart is a circular statistical graphic technique, in which a circle is divided into slices with respect to numerical proportion. In a pie chart, the arc length, central angle, and area of each slice, is proportional to the …

Linux巡检

# uname -a # 查看内核/操作系统/CPU信息 # head -n 1 /etc/issue # 查看操作系统版本 # cat /proc/cpuinfo # 查看CPU信息 # hostname # 查看计算机名 # lspci -tv # 列出所有PCI设备 # lsusb -tv # 列出所有USB设备 # lsmod # 列出加载的内核模块 # env # 查看环境变量 # fre…

appweb ejs_EJS部分

appweb ejsHi! Welcome. Today, we are going to look at EJS partials. EJS Partials help us avoid repetition of the same code on several web pages. 嗨! 欢迎。 今天,我们将看EJS局​​部函数 。 EJS Partials帮助我们避免在多个网页上重复相同的…

Struts2配置

1. 设定server a) window– preferences – myeclipse – servers – tomcat – 6.x b) 选择tomcat homedirectory c) 选择enable d) finish 2. 设定jdk环境 a) window– preferences – java – installed jres b) 如果没有对应的JDK…

ruby继承_Ruby继承

ruby继承Ruby中的继承 (Inheritance in Ruby) Inheritance is a feature of Object Oriented languages in which new classes are derived from existing classes and resulting in the formation of a hierarchy of classes. The derived class is often called as child cla…

Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题

近期在知乎看到一句话,保持学习的有一种是你看到了很多其它的牛人,不甘心,真的不甘心。Spring和hibernate整合的时候,jsp页面做展现,发现展现属性出现: org.apache.jasper.JasperException: could not init…

sql判断数据库类型数据_SQL数据类型

sql判断数据库类型数据SQL | 资料类型 (SQL | Data Types) Just like other programming languages, facilities of defining data of various types are available in SQL also. SQL supports the following data types for the specification of various data-items or field…

同事反馈环:如何实现持续改进的文化

“魔镜魔镜告诉我,谁才是最美丽的人?”,邪恶的皇后如此问道。似乎在精益和敏捷企业中也会有很多与《白雪公主》中类似的问题,如果我们没有一面可以看到我们正在做什么的镜子,我们就很难搞清楚我们有多么美丽&#xff0…

Scala懒惰瓦尔

Scala | 懒惰的瓦尔 (Scala | lazy val) Scala programming language allows the user to initialize a variable as a lazy val. A lazy variable is used when we need to save memory overheads while object creation. Using the lazy keyword, you can halt the initializ…

经典功率谱估计及Matlab仿真

原文出自:http://www.cnblogs.com/jacklu/p/5140913.html 功率谱估计在分析平稳各态遍历随机信号频率成分领域被广泛使用,并且已被成功应用到雷达信号处理、故障诊断等实际工程中。本文给出了经典功率谱估计的几类方法,并通过Matlab的实验仿真…

ruby 三目运算符_Ruby运算符

ruby 三目运算符Ruby运算符 (Ruby operators) Operators are the symbols which assist compiler or interpreter to carry out certain mathematical, logical and relational tasks and produce the results. Operators are method calls with parameters. 运算符是帮助编译器…

极验验证码流程-3.图片加密处理 图片移位

终于把图片加密给搞定了,原理是他把图分成了52个部分,然后通过移动来形成新的图片 主要的位置关系看代码 顺便吐槽下ruby,小众语言就是这么不方便,很多库都没有,百度了半天 最后换成了java来写 图片保存到本地的就不详细说了 主要…

什么是Brouter?

代理:网络设备 (Brouter: A network device) Brouter is a network device, which operates as a combination of both bridge and router. In this single device, a user will get a function of both bridge and router, as it can send out data to create a co…

11gR2 RAC时间同异常导致节点down掉问题处理

实验环境下11204的RAC环境,出现了一个节点DOWN掉的问题。检查日志信息后,在otcssd日志信息发现如下信息:2016-01-17 23:15:20.564: [ CTSS][1175029504]ctsscomm_recv_cb2: Receive incoming message event. Msgtype [3].2016-01-17 23:15…

html-iframe_HTML iframe

html-iframeiframe (Iframes) In HTML, iframes are used to display a webpage inside another webpage. 在HTML中&#xff0c; iframe用于在另一个网页内显示一个网页。 Syntax: 句法&#xff1a; <iframe src"URL"></iframe>The <iframe> tag…

ruby循环_Ruby循环

ruby循环Ruby循环 (Ruby Loops) Loops are comprised of sequentially group instructions which are executed repeatedly until a certain condition is met. Loops provide great help in making the programmers task easier. 循环由顺序执行的组指令组成&#xff0c;这些指…

后缀数组 TYVJ P1860 后缀数组

/*P1860 后缀数组时间: 1000ms / 空间: 131072KiB / Java类名: Main描述 我们定义一个字符串的后缀suffix(i)表示从s[i]到s[length(s)]这段子串。后缀数组&#xff08;Suffix array&#xff09;SA[i]中存放着一个排列&#xff0c;满足suffix(sa[i])<suffix(sa[i1]) 按照字典…