/* * @Company: hugeInfo * @Author: ldh * @Date: 2022-02-16 11:28:12 * @LastEditTime: 2022-02-17 11:18:51 * @LastEditors: ldh * @Version: 1.0.0 * @Description: axios处理方法 */ import axios from 'axios'; import appUrl from './appUrl'; export const ax = axios; export function request(value = {}) { let local = localStorage.getItem('operationToken'); let token = !local ? null : JSON.parse(local); // 无token时 if (!token) { return {}; } axios.defaults.baseURL = appUrl.web; axios.defaults.headers.common['Authorization'] = token; if (value.type == 'get') { return ax .get(value.url, { params: value.data }) .then((response) => { return response; }) .catch(() => { return {}; }); } else { return ax .post(value.url, value.data) .then((response) => { return response; }) .catch(() => { return {}; }); } }