axios的封装
import axios from "axios";
export function request(config) {
return new Promise(((resolve, reject) => {
//1创建axios实例
const instance = axios.create({
baseURL: 'http://123.207.32.32:8000',
timeout: 5000
})
//2 axios拦截器
instance.interceptors.request.use(config => {
//筛选不符合服务器要求的信息
//发送网络请求时候,线上loading
//携带token
return config
}, err => {
})
//2.2响应拦截
instance.interceptors.response.use(res => {
return res.data
}, err => {
})
//3发送网络请求
return instance(config)
}))
}