Browse Source

使用Notification替换原Message

master
李磊 3 years ago
parent
commit
a3c5eb59b5
  1. 14
      src/utils/apibjd.js

14
src/utils/apibjd.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实例
@ -36,7 +36,7 @@ service.interceptors.response.use(
if (res.data.returnCode === 1) { if (res.data.returnCode === 1) {
return res.data.returnData return res.data.returnData
} else if (res.data.returnCode === '20011') { } else if (res.data.returnCode === '20011') {
Message({ Notification({
showClose: true, showClose: true,
message: res.returnMsg, message: res.returnMsg,
type: 'error', type: 'error',
@ -49,7 +49,7 @@ service.interceptors.response.use(
}) })
return Promise.reject('未登录') return Promise.reject('未登录')
} else { } else {
Message({ Notification({
message: res.data.returnMsg || '请求处理异常,请稍后再试', message: res.data.returnMsg || '请求处理异常,请稍后再试',
type: 'error', type: 'error',
duration: 3 * 1000 duration: 3 * 1000
@ -64,7 +64,7 @@ service.interceptors.response.use(
} if (res.returnCode === 1) { } if (res.returnCode === 1) {
return res.returnData return res.returnData
} else if (res.returnCode === '20011') { } else if (res.returnCode === '20011') {
Message({ Notification({
showClose: true, showClose: true,
message: res.returnMsg, message: res.returnMsg,
type: 'error', type: 'error',
@ -88,7 +88,7 @@ service.interceptors.response.use(
if (res.data && res.data.constructor === String) { if (res.data && res.data.constructor === String) {
msg = msg ? msg + ':' + res.data : res.data msg = msg ? msg + ':' + res.data : res.data
} }
Message({ Notification({
message: msg, message: msg,
type: 'error', type: 'error',
duration: 3 * 1000 duration: 3 * 1000
@ -99,8 +99,8 @@ service.interceptors.response.use(
error => { error => {
hideLoading() hideLoading()
console.error('err' + error) // for debug console.error('err' + error) // for debug
Message({ Notification({
message: error.response.data.msg, 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