通过AbortController取消请求,fetch axios通用
async test(data,conifg) {
return this.request.post(`http://localhost:8000/`, data,conifg)
}
//请求config中配置一个signal
// 注意如果取消后需要重新请求 每次请求都要生成一个新的aboutcontroll不然取消后无法再次请求
let cancelControll
const handlerReq = () => {
cancelControll = new AbortController()
// fetch
// fetch('http://localhost:8000/', {
// method: 'post',
// signal: controller.signal
// })
const api = new InvoiceApi()
api.test(null, {signal: cancelControll.signal})
}
const handelCancel = () => {
cancelControll.abort()
}