From 72720eca6d41b8c881d45b7fee181811862346e0 Mon Sep 17 00:00:00 2001 From: "513755565@qq.com" <513755565@qq.com> Date: Sat, 31 Oct 2020 17:09:33 +0800 Subject: [PATCH] fix the interceptor fires repeatedly on chrome 84.0 --- src/api/request.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/api/request.ts b/src/api/request.ts index 97a07f3..3332aaf 100644 --- a/src/api/request.ts +++ b/src/api/request.ts @@ -1,9 +1,11 @@ import axios, { AxiosRequestConfig } from 'axios'; import { message as $message } from 'antd'; -axios.defaults.timeout = 6000; +const axiosInstance = axios.create({ + timeout: 6000 +}); -axios.interceptors.request.use( +axiosInstance.interceptors.request.use( config => { return config; }, @@ -12,7 +14,7 @@ axios.interceptors.request.use( } ); -axios.interceptors.response.use( +axiosInstance.interceptors.response.use( config => { if (config?.data?.message) { // $message.success(config.data.message) @@ -60,9 +62,9 @@ export const request = ( const prefix = ''; url = prefix + url; if (method === 'post') { - return axios.post(url, data, config); + return axiosInstance.post(url, data, config); } else { - return axios.get(url, { + return axiosInstance.get(url, { params: data, ...config });