|
|
|
|
@ -1,7 +1,8 @@
|
|
|
|
|
import axios from 'axios'
|
|
|
|
|
import { MessageBox, Message } from 'element-ui'
|
|
|
|
|
import { MessageBox, Message ,Loading} from 'element-ui'
|
|
|
|
|
import store from '@/store'
|
|
|
|
|
import { getToken } from '@/utils/auth'
|
|
|
|
|
let loading;
|
|
|
|
|
|
|
|
|
|
// create an axios instance
|
|
|
|
|
const service = axios.create({
|
|
|
|
|
@ -13,8 +14,12 @@ const service = axios.create({
|
|
|
|
|
// request interceptor
|
|
|
|
|
service.interceptors.request.use(
|
|
|
|
|
config => {
|
|
|
|
|
// do something before request is sent
|
|
|
|
|
|
|
|
|
|
// do something before request is sent
|
|
|
|
|
loading = Loading.service({
|
|
|
|
|
lock:true,
|
|
|
|
|
background:"rgba(0,0,0,0.4)",
|
|
|
|
|
text:"正在加载中..."
|
|
|
|
|
})
|
|
|
|
|
if (store.getters.token) {
|
|
|
|
|
// let each request carry token
|
|
|
|
|
// ['X-Token'] is a custom headers key
|
|
|
|
|
@ -45,6 +50,7 @@ service.interceptors.response.use(
|
|
|
|
|
* You can also judge the status by HTTP Status Code
|
|
|
|
|
*/
|
|
|
|
|
response => {
|
|
|
|
|
loading.close()
|
|
|
|
|
const res = response.data
|
|
|
|
|
|
|
|
|
|
// if the custom code is not 20000, it is judged as an error.
|
|
|
|
|
@ -74,6 +80,7 @@ service.interceptors.response.use(
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error => {
|
|
|
|
|
loading.close()
|
|
|
|
|
console.log('err' + error) // for debug
|
|
|
|
|
Message({
|
|
|
|
|
message: error.message,
|
|
|
|
|
|