CN-747: http请求支持取消

This commit is contained in:
刘洪洪
2022-10-19 15:27:26 +08:00
parent 111f731712
commit 15cfd48770
6 changed files with 60 additions and 8 deletions

View File

@@ -1,8 +1,20 @@
import axios from 'axios'
import { storageKey } from '@/utils/constants'
import store from '@/store'
const CancelToken = axios.CancelToken
axios.interceptors.request.use(config => {
const token = localStorage.getItem(storageKey.token)
// 添加http请求终止方法
const arr = []
const cancelToken = new CancelToken(function executor (c) {
arr.push(c)
store.commit('setHttpCancel', arr)
})
config.cancelToken = cancelToken
if (token) {
config.headers['Cn-Authorization'] = token // 请求头token
}