在使用Vue-cli3開發(fā)移動(dòng)端的時(shí)候需要注意移動(dòng)端適配的問題
我是使用rem來做的,所以需要使用postcss-px2rem進(jìn)行統(tǒng)一轉(zhuǎn)換
首先需要安裝一下postcss-px2rem:
npm install postcss-px2rem --save-dev
然后在vue.config.js文件(vue.config.js文件在vue-cli3中默認(rèn)是沒有的,需要自己手動(dòng)在根目錄下創(chuàng)建)中添加以下代碼:
module.exports = {
css: {
loaderOptions: {
css: {},
postcss: {
plugins: [
require('postcss-px2rem')({
remUnit: 75//根據(jù)設(shè)計(jì)圖的大小變化,37.5或者75
})
]
}
}
},
}
如果配合了Mint UI框架使用,直接使用上面的方法,會(huì)有問題,因?yàn)镸int UI框架已經(jīng)做了適配了,我們再做一邊就多余了,有兩種方法:
1、如果設(shè)計(jì)圖是750px的,可以將設(shè)計(jì)圖改成375px,或者自己計(jì)算,
2、可以把postcss-px2rem依賴卸掉,安裝依賴postcss-px2rem-exclude,并修改配置文件package.json
"postcss": {
"plugins": {
"autoprefixer": {},
"postcss-px2rem-exclude":{
"remUnit": 75,
"exclude":"/node_modules/i"
}
}
}
參考:
https://blog.csdn.net/weixin_39944458/article/details/84633110
https://blog.csdn.net/qq_42354773/article/details/84629147
https://juejin.im/post/5b8ff8b3e51d450e5a73c033