npm i vant -S
主要问题如何按需引用、REM适配babel-plugin-import 会在编译过程当中将 import 的写法自动转换为按需引入的方式
//安装命令
npm i babel-plugin-import -D
复制代码
//babel.config.js
module.exports = {
presets: [
'@vue/app'
],
plugins: [
['import', {
libraryName: 'vant',
libraryDirectory: 'es',
style: true
}, 'vant']
]
}
复制代码
4.这样就能够直接使用了,在main.js文件夹引入css
import Vue from 'vue'
import { Button } from 'vant';
Vue.use(Button);
复制代码
npm i postcss-pxtorem -S
npm i amfe-flexible -S
复制代码
const autoprefixer = require('autoprefixer');
const pxtorem = require('postcss-pxtorem');
module.exports = {
css:{
sourceMap:false,
loaderOptions: {
postcss: {
plugins: [
autoprefixer(),
pxtorem({
rootValue: 37.5,
propList: ['*']
})
]
}
}
}
}
复制代码
import 'amfe-flexible';
复制代码
这样就能够在html下对于font-size进行计算。达到自适应的,直接安照UI设计稿750px写像素单位,开发更加高效。html