From 1f7dbfb2ca686cafa54cfd7a8ccaa32a7a1b943d Mon Sep 17 00:00:00 2001 From: sa_10_0 <2492740167@qq.com> Date: Wed, 23 Oct 2024 19:51:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/myAxiso.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/api/myAxiso.ts diff --git a/src/api/myAxiso.ts b/src/api/myAxiso.ts new file mode 100644 index 0000000..e1f0785 --- /dev/null +++ b/src/api/myAxiso.ts @@ -0,0 +1,26 @@ +// 创建实例时配置默认值 +import axios from "axios"; +const myAxios = axios.create({ + withCredentials:true, + baseURL: '123.249.108.160:8080/api'//测试服务器 +}); +// 添加请求拦截器 +axios.interceptors.request.use(function (config) { + // 在发送请求之前做些什么 + return config; +}, function (error) { + // 对请求错误做些什么 + return Promise.reject(error); +}); + +// 添加响应拦截器 +axios.interceptors.response.use(function (response) { + // 2xx 范围内的状态码都会触发该函数。 + // 对响应数据做点什么 + return response.data; +}, function (error) { + // 超出 2xx 范围的状态码都会触发该函数。 + // 对响应错误做点什么 + return Promise.reject(error); +}); +export default myAxios