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

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

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

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

因?yàn)榧夹g(shù)總是更新迭代,大多數(shù)博主都沒有習(xí)慣寫上自己的配置,總是把一段自認(rèn)為可以的配置貼出來(lái),很多時(shí)候看了不僅誤人子弟,還耽誤很多開發(fā)時(shí)間,我,致力于做一個(gè)負(fù)責(zé)人的博主,都會(huì)貼出配置和使用環(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計(jì)算,就是這么簡(jiǎn)單。

附上插件的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é)

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

相關(guān)文章

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

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

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

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

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

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

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

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

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

    詳解Vue中CSS樣式穿透問題

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

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

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

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

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

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

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

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

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

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

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

最新評(píng)論

宜兴市| 绥宁县| 中阳县| 交城县| 长顺县| 密山市| 九龙坡区| 保康县| 周口市| 陇川县| 鄂伦春自治旗| 卫辉市| 石渠县| 营山县| 永平县| 建水县| 集贤县| 浏阳市| 西和县| 体育| 冀州市| 湘西| 宿迁市| 宁夏| 郴州市| 烟台市| 永丰县| 宜章县| 乌恰县| 施甸县| 吴川市| 昌吉市| 新兴县| 隆德县| 南昌县| 武川县| 南阳市| 遵义县| 新晃| 巴彦淖尔市| 彰化市|