Vite項目怎么進行屏幕適配?
基于rem的適配方案

1、安裝依賴
npm i postcss-pxtorem autoprefixer amfe-flexible --save-dev
postcss-pxtorem 是PostCSS的插件,用于將像素單元生成rem單位
autoprefixer 瀏覽器前綴處理插件
amfe-flexible 可伸縮布局方案 替代了原先的lib-flexible 選用了當前眾多瀏覽器兼容的viewport
2、項目根目錄創建 postcss.config.js 文件
module.exports = { plugins: { autoprefixer: { overrideBrowserslist: [ "Android 4.1", "iOS 7.1", "Chrome > 31", "ff > 31", "ie >= 8", "last 10 versions", // 所有主流瀏覽器最近10版本用 ], grid: true, }, "postcss-pxtorem": { rootValue: 192, // 設計稿寬度的1/ 10 例如設計稿按照 1920設計 此處就為192 propList: ["*", "!border"], // 除 border 外所有px 轉 rem selectorBlackList: [".el-"], // 過濾掉.el-開頭的class,不進行rem轉換 }, }, };
3、main.ts/js 文件中導入依賴
import "amfe-flexible/index.js";
4、項目重啟
基于scale的適配方案

浙公網安備 33010602011771號