2023-01-05 —— vite_vue3 移動端適配

安裝插件:

安裝postcss-pxtorem

npm install postcss-pxtorem --save-dev

安裝lib-flexible

由于時間的問題,lib-flexible其實已經(jīng)棄用了,現(xiàn)在是使用名為amfe-flexible的插件,amfe-flexible實際上就是在lib-flexible的基礎(chǔ)上更新的,所以用法都是一樣。

npm i -s  amfe-flexible

安裝完畢只需要引入amfe-flexible

引入插件:

main.js文件引入:

import 'amfe-flexible'

創(chuàng)建配置文件:

在根目錄,和package.json同級,創(chuàng)建一個名為postcss.config.js的文件,然后里面的內(nèi)容我直接照搬vant提供的。

如果有這個文件,可以自行修改里面的內(nèi)容,沒有才創(chuàng)建。

module.exports = {
  plugins: {
    autoprefixer: {
      browsers: ['Android >= 4.0', 'iOS >= 8'],
    },
    'postcss-pxtorem': {
      rootValue: 37.5,
      propList: ['*'],
    },
  },
};

然后保存,這個時候我們再去vue里面,對元素設(shè)置px,運行時會發(fā)現(xiàn)網(wǎng)頁上自動轉(zhuǎn)換成了rem單位。

百度到一個新的配置

module.exports = {
  plugins: {
    'autoprefixer': {
      overrideBrowserslist: [
        'Android 4.1',
        'iOS 7.1',
        'Chrome > 31',
        'ff > 31',
        'ie >= 8'
      ]
    },
    'postcss-pxtorem': {
      rootValue: 37.5,
      propList: ['*']
    }
  }
}

黑名單
顧名思義,在黑名單中的類名,將不會自動rem轉(zhuǎn)換

module.exports = {
  plugins: {
    'autoprefixer': {
      overrideBrowserslist: [
        'Android 4.1',
        'iOS 7.1',
        'Chrome > 31',
        'ff > 31',
        'ie >= 8'
      ]
    },
    'postcss-pxtorem': {
      rootValue: 37.5,
      propList: ['*'],
      selectorBlackList: ['.van-notify',],
    }
  }
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容