亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue3如何使用postcss-px-to-viewport適配屏幕

 更新時間:2023年03月29日 09:39:06   作者:王天平·Jason Wong  
這篇文章主要介紹了vue3如何使用postcss-px-to-viewport適配屏幕問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

本教程只使用于vue3+vue-cli5創(chuàng)建的項目,說白了就是使用的webpack環(huán)境,不適用于vite,后面會更新。

因為技術(shù)總是更新迭代,大多數(shù)博主都沒有習(xí)慣寫上自己的配置,總是把一段自認(rèn)為可以的配置貼出來,很多時候看了不僅誤人子弟,還耽誤很多開發(fā)時間,我,致力于做一個負(fù)責(zé)人的博主,都會貼出配置和使用環(huán)境,方便大家做參考。

使用環(huán)境

名稱版本
vue3.2.13
vue-cli5.x
webpack5.x
nodejs16.15
postcss-px-to-viewport^1.1.1

安裝

npm install postcss-px-to-viewport --save-dev
yarn add postcss-px-to-viewport --save-dev
pnpm add postcss-px-to-viewport --save-dev

如果devserver正在運(yùn)行,安裝完成以后記得重啟devserver。

配置

在項目根目錄下創(chuàng)建 postcss.config.js 文件,并填入一下內(nèi)容:

module.exports = {
  plugins: {
    // ...
    'postcss-px-to-viewport': {
      // options
      unitToConvert: "px",
      viewportWidth: 1920,
      viewportHeight:1080,
      unitPrecision: 3,
      propList: [
        "*"
      ],
      viewportUnit: "vw",
      fontViewportUnit: "vw",
      selectorBlackList: [],
      minPixelValue: 1,
      mediaQuery: false,
      replace: true,
      exclude: /(\/|\\)(node_modules)(\/|\\)/,
    }
  }
}

重新運(yùn)行,打開瀏覽器查看屬性值已經(jīng)變?yōu)関w計算,就是這么簡單。

附上插件的github地址: https://github.com/evrone/postcss-px-to-viewport

項目類型描述
unitToConvert(String)unit to convert, by default, it is px.
viewportWidth(Number)The width of the viewport.
unitPrecision(Number)The decimal numbers to allow the vw units to grow to.
propList(Array)- The properties that can change from px to vw.
-Values need to be exact matches.
Use * at the start or end of a word. (['position'] will match background-position-y)
Use ! to not match a property. Example: ['*', '!letter-spacing']
Combine the "not" prefix with the other prefixes. Example: ['', '!font']
viewportUnit(String)Expected units.
fontViewportUnit(String)Expected units for font.
selectorBlackList(Array)The selectors to ignore and leave as px.If value is string, it checks to see if selector contains the string. ['body'] will match .body-class
If value is regexp, it checks to see if the selector matches the regexp. [/^body$/] will match body but not .body
minPixelValue(Number)Set the minimum pixel value to replace.
mediaQuery(Boolean)replaces rules containing vw instead of adding fallbacks
exclude(Regexp or Array of Regexp Ignore some files like 'node_modules')If value is regexp, will ignore the matches files.
If value is array, the elements of the array are regexp.
include(Regexp or Array of Regexp) If include is set, only matching files will be converted, for example, only files under src/mobile/ (include: /\/src\/mobile\//)If value is array, the elements of the array are regexp.
If value is regexp, will ignore the matches files.
landscape(Boolean)Adds @media (orientation: landscape) with values converted via landscapeWidth.
landscapeUnit(String)Expected unit for landscape option
landscapeWidth(Number)Viewport width for landscape orientation.

總結(jié)

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • vue項目main.js配置及使用方法

    vue項目main.js配置及使用方法

    main.js是項目的入口文件,項目中所有的頁面都會加載main.js,本文主要介紹了vue項目main.js配置及使用方法,非常具有實用價值,需要的朋友可以參考下
    2023-05-05
  • vue3和vue2掛載實例到全局(自定義消息提示框組件方式)

    vue3和vue2掛載實例到全局(自定義消息提示框組件方式)

    這篇文章主要介紹了vue3和vue2掛載實例到全局(自定義消息提示框組件方式),具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2024-04-04
  • VUE腳手架的下載和配置步驟詳解

    VUE腳手架的下載和配置步驟詳解

    這篇文章主要介紹了VUE腳手架下載和配置,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-04-04
  • 使用vue2.6實現(xiàn)抖音【時間輪盤】屏保效果附源碼

    使用vue2.6實現(xiàn)抖音【時間輪盤】屏保效果附源碼

    前段時間看抖音,有人用時間輪盤作為動態(tài)的桌面壁紙,一時間成為全網(wǎng)最火的電腦屏保,后來小米等運(yùn)用市場也出現(xiàn)了【時間輪盤】,有點(diǎn)像五行八卦,感覺很好玩,于是突發(fā)奇想,自己寫一個網(wǎng)頁版小DEMO玩玩,需要的朋友可以參考下
    2019-04-04
  • vue中進(jìn)入詳情頁記住滾動位置的方法(keep-alive)

    vue中進(jìn)入詳情頁記住滾動位置的方法(keep-alive)

    今天小編就為大家分享一篇vue中進(jìn)入詳情頁記住滾動位置的方法(keep-alive),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • Vue中的ESLint配置方式

    Vue中的ESLint配置方式

    這篇文章主要介紹了Vue中的ESLint配置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-03-03
  • 去除element-ui下拉框的下拉箭頭的實現(xiàn)

    去除element-ui下拉框的下拉箭頭的實現(xiàn)

    我們最開始拿到的element-ui是帶有下拉箭頭的,那么如何去除element-ui下拉框的下拉箭頭的實現(xiàn),本文就詳細(xì)的介紹一下,感興趣的可以了解一下
    2023-08-08
  • vue?el-table中使用el-select選中后無效的解決

    vue?el-table中使用el-select選中后無效的解決

    這篇文章主要介紹了vue?el-table中使用el-select選中后無效的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • vue3中關(guān)于路由hash與History的設(shè)置

    vue3中關(guān)于路由hash與History的設(shè)置

    這篇文章主要介紹了vue3中關(guān)于路由hash與History的設(shè)置方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-08-08
  • 深入理解vue中的slot與slot-scope

    深入理解vue中的slot與slot-scope

    這篇文章主要介紹了vue中的slot與slot-scope的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-04-04

最新評論