import axios from 'axios' const service = axios.create({ baseURL: '', timeout: 10000 }) // 请求拦截器 service.interceptors.request.use(config => { // 暂时先写死token 实际项目中再调整token的获取位置 const token = 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjE5ODY2ODgzMjY1MjAwNTc4NTcsImFjY291bnQiOiJieHp0IiwidXVpZCI6ImMyY2E5OGU4LTIyYzItNGZmZi1hZWE0LTBiNWNiZmE4YjNlMSIsInJlbWVtYmVyTWUiOnRydWUsImV4cGlyYXRpb25EYXRlIjoxNzYyNzgzOTkwMzUxLCJvdGhlcnMiOm51bGwsInN1YiI6IjE5ODY2ODgzMjY1MjAwNTc4NTciLCJpYXQiOjE3NjI3NTUxOTAsImV4cCI6MTc2Mjc4Mzk5MH0.zqQcAE08fr2jQd7HcQ9Y3i-gWb2TrCWuUxSzl1kXOoJe2rp1Yly0ffrY6_1jY0ybHJwihONChqiSc-8jRTKYKw' // const token = localStorage.getItem('token'); if (token) { config.headers.Authorization = `${token}`; } return config; }, error => { return Promise.reject(error); }); export async function request(config) { try { const res = await service(config) if (res === null || res === undefined) { return res } if (Object.prototype.hasOwnProperty.call(res, 'data')) { return res.data } } catch (error) { console.log(error) return null } }