vue-cli 3.0+vant項(xiàng)目使用postcss-pxtorem和amfe-flexible 進(jìn)行移動(dòng)端適配

vue-cli 3.0+vant項(xiàng)目使用postcss-pxtorem和amfe-flexible 進(jìn)行移動(dòng)端適配

Rem 適配

Vant 中的樣式默認(rèn)使用px作為單位,如果需要使用rem單位,推薦使用以下兩個(gè)工具

postcss-pxtorem?是一款postcss插件,用于將單位轉(zhuǎn)化為rem

lib-flexible? 用于設(shè)置rem基準(zhǔn)值

lib-flexible已經(jīng)廢棄會(huì)出現(xiàn)很多問(wèn)題,用amfe-flexible進(jìn)行替代


步驟

1. 安裝postcss-pxtorem

$ npm install postcss-pxtorem --save-dev

2. 安裝amf-flexible

$ npm i -S? amfe-flexible

3.在main.js中引入amfe-flexible

$ import 'amfe-flexible'

4. 在vue.config.js中進(jìn)行配置

module.exports = { css: { loaderOptions: { postcss: { plugins: [ require('postcss-pxtorem')({ // 把px單位換算成rem單位 rootValue: 37.5, // vant官方使用的是37.5 selectorBlackList: ['vant', 'mu'], // 忽略轉(zhuǎn)換正則匹配項(xiàng) propList: ['*'] }) ] } } },}


地址

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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