最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

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

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

因?yàn)榧夹g(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。

配置

在項(xiàng)目根目錄下創(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

項(xiàng)目類型描述
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)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • 詳解Vue CLI3 多頁應(yīng)用實(shí)踐和源碼設(shè)計

    詳解Vue CLI3 多頁應(yīng)用實(shí)踐和源碼設(shè)計

    這篇文章主要介紹了詳解Vue CLI3 多頁應(yīng)用實(shí)踐和源碼設(shè)計,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-08-08
  • 淺析前端路由簡介以及vue-router實(shí)現(xiàn)原理

    淺析前端路由簡介以及vue-router實(shí)現(xiàn)原理

    路由就是用來跟后端服務(wù)器進(jìn)行交互的一種方式,通過不同的路徑,來請求不同的資源,請求不同的頁面是路由的其中一種功能。這篇文章主要介紹了前端路由簡介以及vue-router實(shí)現(xiàn)原理,需要的朋友可以參考下
    2018-06-06
  • 圖文講解用vue-cli腳手架創(chuàng)建vue項(xiàng)目步驟

    圖文講解用vue-cli腳手架創(chuàng)建vue項(xiàng)目步驟

    本次小編給大家?guī)淼氖顷P(guān)于用vue-cli腳手架創(chuàng)建vue項(xiàng)目步驟講解內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。
    2019-02-02
  • 對vue事件的延遲執(zhí)行實(shí)例講解

    對vue事件的延遲執(zhí)行實(shí)例講解

    今天小編就為大家分享一篇對vue事件的延遲執(zhí)行實(shí)例講解,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • 詳解Vue中CSS樣式穿透問題

    詳解Vue中CSS樣式穿透問題

    這篇文章主要介紹了VUE中CSS樣式穿透問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-09-09
  • Vue在H5 項(xiàng)目中使用融云進(jìn)行實(shí)時個人單聊通訊

    Vue在H5 項(xiàng)目中使用融云進(jìn)行實(shí)時個人單聊通訊

    這篇文章主要介紹了Vue在H5 項(xiàng)目中使用融云進(jìn)行實(shí)時個人單聊通訊,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2020-12-12
  • 基于vue實(shí)現(xiàn)頁面滾動加載的示例詳解

    基于vue實(shí)現(xiàn)頁面滾動加載的示例詳解

    頁面內(nèi)容太多會導(dǎo)致加載速度過慢,這時可考慮使用滾動加載即還沒有出現(xiàn)在可視范圍內(nèi)的內(nèi)容塊先不加載,出現(xiàn)后再加載,所以本文給大家介紹了基于vue實(shí)現(xiàn)頁面滾動加載的示例,需要的朋友可以參考下
    2024-01-01
  • vue3+TypeScript+vue-router的使用方法

    vue3+TypeScript+vue-router的使用方法

    本文詳細(xì)講解了vue3+TypeScript+vue-router的使用方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2022-01-01
  • vue獲取data數(shù)據(jù)改變前后的值方法

    vue獲取data數(shù)據(jù)改變前后的值方法

    今天小編就為大家分享一篇vue獲取data數(shù)據(jù)改變前后的值方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-11-11
  • vue中vant組件樣式失效問題及解決

    vue中vant組件樣式失效問題及解決

    這篇文章主要介紹了vue中vant組件樣式失效問題及解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04

最新評論

林甸县| 金坛市| 富川| 滨州市| 天祝| 泾阳县| 霍城县| 嫩江县| 荆州市| 安康市| 裕民县| 巧家县| 自贡市| 万源市| 渝中区| 河源市| 新宾| 黄大仙区| 和顺县| 巴楚县| 永兴县| 盖州市| 合阳县| 尤溪县| 通化县| 雅安市| 通榆县| 仪陇县| 曲阳县| 尼玛县| 忻州市| 比如县| 漾濞| 汪清县| 祁门县| 永登县| 黄浦区| 陈巴尔虎旗| 攀枝花市| 新巴尔虎左旗| 游戏|