vue引入postcss-plugin-px2rem,px轉rem

npm install --save-dev postcss-plugin-px2rem

vue.config.js

module.exports = {css: {loaderOptions: {postcss: {plugins: [require('postcss-plugin-px2rem')({rootValue: 16, //換算基數, 默認100  ,1 / fontsize(html) = x 原來的1px轉為0.0625rem// unitPrecision: 5, //允許REM單位增長到的十進制數字。//propWhiteList: [],  //默認值是一個空數組,這意味著禁用白名單并啟用所有屬性。// propBlackList: [], //黑名單// exclude: /(node_modules)/,  //默認false,可以(reg)利用正則表達式排除某些文件夾的方法,例如/(node_module)/ 。如果想把前端UI框架內的px也轉換成rem,請把此屬性設為默認值// selectorBlackList: [], //要忽略并保留為px的選擇器// ignoreIdentifier: false,  //(boolean/string)忽略單個屬性的方法,啟用ignoreidentifier后,replace將自動設置為true。// replace: true, // (布爾值)替換包含REM的規則,而不是添加回退。// mediaQuery: false,  //(布爾值)允許在媒體查詢中轉換px。// minPixelValue: 3 //設置要替換的最小像素值(3px會被轉rem)。 默認 0//exclude: "/node_modules/",// selectorBlackList: ['html', 'mint-', 'mt-', 'mpvue-', 'calendar', 'iconfont'], //在rem.js全局作用下   排除指定的文件的影響// propBlackList: ['border']})]}}}
}
  • 以上完成px->rem,為了某些已經以rem為單位的組件不受影響,如消息框圖標,這里將rootValue設置為html默認字體大小16px(html根字體大小代表rem代表的大小,此時1rem=16px)
  • main.js中引入rem.js,監聽窗口變化,等比例改變根fontsize達到改變rem的大小

rem.js

// 設置 rem 函數
function setRem() {let htmlWidth = document.documentElement.clientWidth// let htmlHeight = document.documentElement.clientHeight//得到html的Dom元素let htmlDom = document.getElementsByTagName('html')[0];// //設置根元素字體大小 937 / 16 = 58.5625 , 937是谷歌1080 - 工具欄高度// htmlDom.style.fontSize = (htmlHeight / 58.5625) + 'px';//設置根元素字體大小 1920 / 16 = 120htmlDom.style.fontSize = (htmlWidth / 120) + 'px';
}
// 初始化
setRem();
// 改變窗口大小時重新設置 rem
window.onresize = function () {setRem()
}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/278588.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/278588.shtml
英文地址,請注明出處:http://en.pswp.cn/news/278588.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

HikariCP連接池配置

2019獨角獸企業重金招聘Python工程師標準>>> HikariCP號稱性能最好的Java數據庫連接池。雖沒做過親測但是公司項目一直在用,大概經歷過2萬左右用戶同時在線,鏈接池性能方面未出現問題。 官網:http://brettwooldridge.github.io/Hi…

Microsoft Desktop Player是IT Pro的寶貴工具

If you are an IT Professional, a new education tool introduced by Microsoft is the MS Desktop Player. Today we take a look at what it has to offer, from Webcasts, White Papers, Training Videos, and more. 如果您是IT專業人員,則Microsoft推出的新的培…

如何在Microsoft Excel中將文本轉換為日期值

Analysis of business data often requires working with date values in Excel to answer questions such as “how much money did we make today” or “how does this compare to the same day last week?” And that can be hard when Excel doesn’t recognize the valu…

git針對已有倉庫或已有文件的初始化操作

git全局配置用戶 git config --global user.name “xxx” git config --global user.email “xxx.cn” 情況1、存在git倉庫 git clone url.git //cd xx //touch README.md //git add README.md //git commit -m "add README" //git push -u origin master情況2、已…

策略模式-Golang實現

目的:根據不同策略來執行對象的相應操作 和工廠模式很像,不同點在于: 工廠模式是傳入參數后創建對象,根據傳入的參數寫邏輯來判斷應該創建什么類型的對象,模式的使用者調用對象統一的方法操作。 策略模式是模式的使用者…

看著手機會讓您暈眩嗎? 禁用動畫

Giulio_Fornasar/ShutterstockGiulio_Fornasar /快門Are your phone’s buttery-smooth animations causing motion sickness, eyestrain, or even slow app performance? Those animations are just for looks, and you can disable a lot of them on both iPhone and Androi…

電腦的組成

一、按電腦組成分 1.CPU(中央處理器),是一塊超大規模的集成電路,有很多針腳,是電腦的核心,它是電腦進行運算和控制的核心,處理著各種信息的運算,就像人計算數學題要用頭腦運算一樣。…

【云周刊】第139期:阿里年會黑科技全揭秘:IoT手環、人臉識別驗票、大屏彈幕互動等“十八般武藝”輪番上陣...

摘要:阿里年會黑科技全揭秘:IoT手環、人臉識別驗票、大屏彈幕互動等“十八般武藝”輪番上陣,2017上半年無監督特征學習研究成果匯總,CDN最全學習教程,量子計算會帶來什么樣的革命?更多精彩技術資訊&#xf…

微信小程序之 SideBar(側欄分類)

項目目錄: 模擬數據: utils / data.js function getSData() {var data [{"id": 1,"tree": {"id": 1,"desc": "寶寶奶粉","desc2": null,"level": "level1","log…

騰訊地圖判斷點是否在區域內

鏈接添加幾何計算庫&#xff1a;librariesgeometry xxx為自己的key <script charset"utf-8" src"https://map.qq.com/api/gljs?v1.exp&keyxxx&librariesgeometry"></script>調用 TMap.geometry.isPointInPolygon(position, paths)

如何在線查找成千上萬的免費電子書

You’ve got an ebook reader (or a laptop or netbook with ebook reading software) now you just need some free books to put it to good use. Read on as we show you the best places to score free books online. 您已經有了一個電子書閱讀器(或帶有電子書閱讀軟件的筆…

【SDOI2008】儀仗隊

題面 題解 當$(x,y)$能被看到時&#xff0c;$gcd(x,y)1$&#xff0c; 所以可以求$\sum_{i0}^n\sum_{j0}^n[gcd(x,y)1]$ 或者用歐拉函數 代碼 #include<bits/stdc.h> #define RG register #define clear(x, y) memset(x, y, sizeof(x)); using namespace std;template<…

kbone-cli初始化項目,提示‘模板xx不存在’

取消git代理就好了 git config --global --unset http.proxygit config --global --unset https.proxykbone init my-app跳轉目錄 cd my-app開發小程序 npm run mp開發 Web npm run web 發布 Web npm run build恭喜你! "my-app"項目初始化成功!

Spring Bean默認配置為單實例 Spring Bean生命周期

2019獨角獸企業重金招聘Python工程師標準>>> Spring 的Bean默認的是單例的. 如果不想單例需要如下配置&#xff1a; <bean id"user" class"..." scope"singleton"/> scope"singleton"就是配置這個bean是單例的&#…

minecraft服務器_如何啟動自己的Minecraft服務器進行多人游戲

minecraft服務器If you’ve played Minecraft, then it’s easy to see how much fun it can be. Running your own server lets you bring all of your friends into the same game, and you can play with rules you get to make or break. It’s the ultimate in an already…

Spring Boot 2.x(六):優雅的統一返回值

目錄 為什么要統一返回值ReturnVOReturnCode使用ReturnVO使用AOP進行全局異常的處理云擼貓公眾號為什么要統一返回值 在我們做后端應用的時候&#xff0c;前后端分離的情況下&#xff0c;我們經常會定義一個數據格式&#xff0c;通常會包含code&#xff0c;message&#xff0c;…

Object defineProperty

Object defineProperty一、簡介1. 屬性表2.互斥性3. get、set的簡單使用二、深入1.定義常量2. Object.preventExtensions() 禁止對象拓展(不可逆)3. Object.seal() 密封(不可逆)4. Object.freeze() 凍結(不可逆)三、應用一、簡介 defineProperty可以詳細的配置一個對象的屬性的…

jhope代碼分析以及網站結構

如下圖所示&#xff0c;為Extjs部分代碼提供的網頁結構&#xff1a;網站看上去本來是這樣的前端采用ExtJS&#xff0c;與后臺的SpringMVCSpringHibernate進行數據交互。之前分析過登錄的過程&#xff0c;不贅述在loginController處理登錄返回結果的最后&#xff0c;如下語句也就…

Ubuntu下Authentication token manipulation error或者Authentication Failure解決辦法

在Ubuntu18.04使用以下命令出現以下錯誤: 用passwd為新建用戶或者root添加密碼:Authentication token manipulation error 切換root用戶出現Authentication Failure. 網上出現了大致兩種方法: 第一種&#xff1a;用戶文件和密碼文件被保護&#xff0c;用chattr命令移除保護即可…

初學者:如何使用虛擬PC將Windows 7安裝到虛擬機

Continuing in our series covering how to use Virtual PC, this week we’ll be showing you how to install Windows 7 into a virtual machine. It’s a very simple process, but here’s the step-by-step guide for beginners. 繼續我們的系列文章&#xff0c;介紹如何使…