Browse Source

优化响应报错提醒,并Message更换为Notification

master
李磊 3 years ago
parent
commit
76f10c4c2c
  1. 12
      src/utils/api.js

12
src/utils/api.js

@ -1,5 +1,5 @@
import axios from 'axios' import axios from 'axios'
import { Message } from 'element-ui' import { Notification } from 'element-ui'
import store from '../store' import store from '../store'
import { showLoading, hideLoading } from './apiHelper' import { showLoading, hideLoading } from './apiHelper'
// 创建axios实例 // 创建axios实例
@ -40,7 +40,7 @@ service.interceptors.response.use(
} else if (res.returnCode === 1) { } else if (res.returnCode === 1) {
return res.returnData return res.returnData
} else if (res.code === 20001) { } else if (res.code === 20001) {
Message({ Notification({
showClose: true, showClose: true,
message: res.message, message: res.message,
type: 'error', type: 'error',
@ -61,7 +61,7 @@ service.interceptors.response.use(
} else { } else {
msg = res.returnMsg msg = res.returnMsg
} }
Message({ Notification({
message: msg, message: msg,
type: 'error', type: 'error',
duration: 3 * 1000 duration: 3 * 1000
@ -71,9 +71,9 @@ service.interceptors.response.use(
}, },
error => { error => {
hideLoading() hideLoading()
console.error('err' + error)// for debug console.error('error', error.response)// for debug
Message({ Notification({
message: error.message, message: error.response.data && error.response.data.message ? error.response.data.message : error.message,
type: 'error', type: 'error',
duration: 3 * 1000 duration: 3 * 1000
}) })

Loading…
Cancel
Save