mirror of
https://gitee.com/dapppp/ruoyi-plus-vben5.git
synced 2026-03-27 19:43:23 +08:00
fix(upload): 修复组件卸载时未正确中止所有上传请求的问题
将单个AbortController改为存储多个中止函数,确保所有上传请求都能在组件卸载时被正确中止
This commit is contained in:
@@ -271,7 +271,7 @@ export function useUpload(
|
|||||||
return file;
|
return file;
|
||||||
};
|
};
|
||||||
|
|
||||||
const uploadAbort = new AbortController();
|
const abortList: (() => void)[] = [];
|
||||||
/**
|
/**
|
||||||
* 自定义上传实现
|
* 自定义上传实现
|
||||||
* @param info
|
* @param info
|
||||||
@@ -291,6 +291,7 @@ export function useUpload(
|
|||||||
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
const percent = Math.trunc((e.loaded / e.total!) * 100);
|
||||||
info.onProgress!({ percent });
|
info.onProgress!({ percent });
|
||||||
});
|
});
|
||||||
|
abortList.push(apiInstance.abort);
|
||||||
const res = await apiInstance;
|
const res = await apiInstance;
|
||||||
info.onSuccess!(res);
|
info.onSuccess!(res);
|
||||||
if (props.showSuccessMsg) {
|
if (props.showSuccessMsg) {
|
||||||
@@ -304,7 +305,8 @@ export function useUpload(
|
|||||||
};
|
};
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
props.abortOnUnmounted && uploadAbort.abort();
|
props.abortOnUnmounted && abortList.forEach((abort) => abort());
|
||||||
|
abortList.length = 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user