| | |
| | | import pkg from '../../package' |
| | | import { trim } from './util' |
| | | import cache from '../plugins/cache' |
| | | import { Message } from 'element-ui' |
| | | |
| | | axios.defaults.headers.common['Content-Type'] = 'application/json;charset=UTF-8' |
| | | const axiosInstance = axios.create({ |
| | |
| | | |
| | | // 新建请求拦截器 |
| | | axiosInstance.interceptors.request.use(config => { |
| | | console.log(config); |
| | | console.log(config) |
| | | // debugger |
| | | // 参数去空格 |
| | | if (config.trim === true) { |
| | |
| | | |
| | | // 新建响应拦截器 |
| | | axiosInstance.interceptors.response.use((response) => { |
| | | // debugger |
| | | // 请求失败 |
| | | if (response.status !== 200) { |
| | | return Promise.reject(new Error('服务器繁忙,请稍后再试')) |
| | |
| | | } |
| | | // 业务失败 |
| | | if (!response.data.success) { |
| | | Message.error(response.data.message) |
| | | return Promise.reject(response.data) |
| | | } |
| | | return response.data.data |