您好,登錄后才能下訂單哦!
這篇文章主要講解了“vue3怎么使用postcss-px-to-viewport適配屏幕”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“vue3怎么使用postcss-px-to-viewport適配屏幕”吧!
名稱 | 版本 |
---|---|
vue | 3.2.13 |
vue-cli | 5.x |
webpack | 5.x |
nodejs | 16.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正在運行,安裝完成以后記得重啟devserver。
在項目根目錄下創建 postcss.config.js 文件,并填入一下內容:
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)(\/|\\)/, } } }
重新運行,打開瀏覽器查看屬性值已經變為vw計算,就是這么簡單。
項目 | 類型 | 描述 |
---|---|---|
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. |
感謝各位的閱讀,以上就是“vue3怎么使用postcss-px-to-viewport適配屏幕”的內容了,經過本文的學習后,相信大家對vue3怎么使用postcss-px-to-viewport適配屏幕這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。