猛跑小猪
import store from '../store/store'import axios from 'axios'import {SET_TOAST_INFO, SET_LOADING_STATE} from '../store/type'axios.interceptors.request.use(config => { return config}, error => { store.commit(SET_TOAST_INFO, { mode: 'danger', title: '貌似网络出错了,麻烦您检查下网络是否良好再来试试吧!' }); return Promise.reject(error)})// http响应拦截器axios.interceptors.response.use(data => { return data.data;}, error => { if (error.response) { store.commit(SET_LOADING_STATE, false); switch (error.response.status) { case 401: store.commit(SET_TOAST_INFO, { mode: 'danger', title: '您还没有登陆呢,马上进行登陆吧' }); window.location.href = '/#/login'; break; default: store.commit(SET_TOAST_INFO, { mode: 'danger', title: '貌似网络出错了,麻烦您检查下网络是否良好再来试试吧!' }); break; } }})