From c34d45de52c057df82b344945882a8018e308bee Mon Sep 17 00:00:00 2001 From: liuyx <1517482303@qq.com> Date: Tue, 29 Nov 2022 21:18:03 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=81=E8=A3=85axios=E8=AF=B7=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- admin/src/utils/request.js | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 admin/src/utils/request.js diff --git a/admin/src/utils/request.js b/admin/src/utils/request.js new file mode 100644 index 0000000..2f0020f --- /dev/null +++ b/admin/src/utils/request.js @@ -0,0 +1,28 @@ +import axios from 'axios' +import { ElMessage } from 'element-plus' + +const request = axios.create({ + baseURL: '/api', + timeout: 3000 +}) + +// 添加请求拦截器 +request.interceptors.request.use(function (config) { + return config +}, function (error) { + // 对请求错误做些什么 + return Promise.reject(error) +}) + +// 添加响应拦截器 +request.interceptors.response.use((response) => { + return response +}, (error) => { + ElMessage({ + type: 'error', + message: '出错啦!' + }) + return Promise.reject(error) +}) + +export default request