From 8e93686e4cc4b339490949e52bdbbd7c933fbf76 Mon Sep 17 00:00:00 2001 From: liuyx <1517482303@qq.com> Date: Wed, 28 Dec 2022 14:36:53 +0800 Subject: [PATCH] =?UTF-8?q?axios=E5=B0=81=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/utils/request.js | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/admin/src/utils/request.js b/admin/src/utils/request.js index 2f0020f..a482488 100644 --- a/admin/src/utils/request.js +++ b/admin/src/utils/request.js @@ -7,22 +7,30 @@ const request = axios.create({ }) // 添加请求拦截器 -request.interceptors.request.use(function (config) { - return config -}, function (error) { - // 对请求错误做些什么 - return Promise.reject(error) -}) +request.interceptors.request.use( + (config) => { + return config + }, + (error) => { + // 对请求错误做些什么 + return Promise.reject(error) + } +) // 添加响应拦截器 -request.interceptors.response.use((response) => { - return response -}, (error) => { - ElMessage({ - type: 'error', - message: '出错啦!' - }) - return Promise.reject(error) -}) +request.interceptors.response.use( + (response) => { + console.log(response.data) + return response.data + }, + (error) => { + ElMessage({ + type: 'error', + message: '出错啦!' + }) + console.error(error) + return Promise.reject(error) + } +) export default request