1.下载依赖
- lib-flexible
//移动端适配依赖
npm install lib-flexible
- postcss-px2rem
//px转rem依赖
npm install postcss-pxtorem
2.配置postcss-px2rem
//vue.config.js
module.exports = {
css: {
loaderOptions: {
css: {},
postcss: {
plugins: [
require('postcss-px2rem')({
remUnit: 37.5
})
]
}
}
},
devServer: {
open: true,
port: 8888
}
}
4.使用 lib-flexible
//main.js
import 'lib-flexible'
完成上述操作的情况下,项目都会自适应所有移动设备