搭建项目(h5 自适应)
- 安装 lib-flexible
npm install lib-flexible --save-dev
在main.js中引入lib-flexible
- 安装 postcss-pxtorem 并配置(创建postcss.config.js文件)
npm install postcss-pxtorem --save-dev
2)配置postcss.config
module.exports = {
plugins: {
'autoprefixer': {
browsers: ['Android >= 4.0', 'iOS >= 8']
},
'postcss-pxtorem': {
rootValue: 37.5,
propList: ['*']
}
},
/*
* 如果设计稿的尺寸不是 375,而是 750 或其他大小,(postcss-pxtorem 插件的版本需要 >= 5.0.0)可以将 rootValue 配置调整为:
*/
// plugins: {
// 'postcss-pxtorem': {
// rootValue({ file }) {
// return file.indexOf('vant') !== -1 ? 37.5 : 75;
// },
// propList: ['*'],
// },
// },
}
- 封装axios
import axios from 'axios'
import {
toast } from 'vant'
import 'vant/lib/index.css'
const service = axios