From a193e3b66b1bff84a625d5c598e40f876a697c3b Mon Sep 17 00:00:00 2001 From: ronger Date: Mon, 7 Dec 2020 23:56:33 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E8=AF=B7=E6=B1=82=E8=BF=94=E5=9B=9E?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E5=A4=84=E7=90=86,=E6=8F=90=E7=A4=BA?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=97=AE=E9=A2=98=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/axios.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/plugins/axios.js b/plugins/axios.js index 76a8a36..3fbdf94 100644 --- a/plugins/axios.js +++ b/plugins/axios.js @@ -1,11 +1,13 @@ +import {Message} from 'element-ui' + const Cookie = require('js-cookie') export default function ({app, $axios, store, redirect}) { $axios.onRequest(config => { let token = store.state.oauth?.accessToken; if (token) { - if (!(config.url.indexOf('console') > -1 || config.url.indexOf('comments') > -1)) { - config.headers['Authorization'] = store.state.oauth?.accessToken - } + // if (!(config.url.indexOf('console') > -1 || config.url.indexOf('comments') > -1)) { + // } + config.headers['Authorization'] = token } }) $axios.onResponse(response => { @@ -20,18 +22,18 @@ export default function ({app, $axios, store, redirect}) { if (response.data.success) { resolve(response.data); } else { - if (response.data.code === '0') { - app.$message(message); - } else if (response.data.code === '401') { + if (response.data.code === 0) { + Message.error(message ? message : '服务异常') + } else if (response.data.code === 401) { Cookie.remove('auth') store.commit('setAuth', null); - } else if (response.data.code === '402') { + } else if (response.data.code === 402) { Cookie.remove('auth') store.commit('setAuth', null); - } else if (response.data.code === '404') { - app.$message('操作失败,请稍后再试......') - } else if (response.data.code === '500') { - app.$message('服务器正在开小差,请稍后再试......') + } else if (response.data.code === 404) { + Message.error('操作失败,请稍后再试......') + } else if (response.data.code === 500) { + Message.error('服务器正在开小差,请稍后再试......') } } reject(response);