vue移動(dòng)端項(xiàng)目中使用postcss-pxtorem進(jìn)行適配方案

首先,我們先使用vue-cli創(chuàng)建一個(gè)初始化的vue項(xiàng)目。

vue create hello-world

當(dāng)項(xiàng)目創(chuàng)建好以后,我們在根目錄下新建一個(gè)vue.config.js,想必大家也都懂這個(gè)文件是干什么的。

既然是使用postcss-pxtorem對移動(dòng)端項(xiàng)目進(jìn)行適配,那肯定先要安裝它,于是我們在電腦上敲下這行命令

npm install postcss-pxtorem -D

postcss-pxtorem有一個(gè)好伙伴amfe-flexible,也需要一并安裝。

npm install amfe-flexible -D

當(dāng)我們安裝好這兩個(gè)依賴以后呢,我們就要使用它們了,先在main.js中引入amfe-flexible

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

// 引入amfe-flexible
import 'amfe-flexible/index'
 
Vue.config.productionTip = false
 
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

然后我們在vue.config.js文件中對postcss-pxtorem進(jìn)行配置。

const autoprefixer = require('autoprefixer')  // 這個(gè)依賴不用安裝
const pxtorem = require('postcss-pxtorem')
 
module.exports = {
  css: {
    loaderOptions: {
      postcss: {
        plugins: [
          autoprefixer(),
          pxtorem({
            rootValue: 37.5,  // 根字體大小,如果設(shè)計(jì)圖是750的話 記得除2
            unitPrecision: 5,
            propList: ['*'], // 作用在哪些屬性上 我這里用的是通配符
            selectorBlackList: ['vant-'], // 將哪些html元素排除在外,我這里添加了一個(gè)vant的
            replace: true,
            mediaQuery: false,
            minPixelValue: 0,
            exclude: /node_modules/i
          })
        ]
      }
    }
  }
}

原文鏈接:https://blog.csdn.net/g1197410313/article/details/107727431

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

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

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