fix(upload): 修复组件卸载时未正确中止所有上传请求的问题

将单个AbortController改为存储多个中止函数,确保所有上传请求都能在组件卸载时被正确中止
This commit is contained in:
dap
2026-01-20 11:08:35 +08:00
parent 3582807910
commit efbd8e9bd1

View File

@@ -271,7 +271,7 @@ export function useUpload(
return file;
};
const uploadAbort = new AbortController();
const abortList: (() => void)[] = [];
/**
* 自定义上传实现
* @param info
@@ -291,6 +291,7 @@ export function useUpload(
const percent = Math.trunc((e.loaded / e.total!) * 100);
info.onProgress!({ percent });
});
abortList.push(apiInstance.abort);
const res = await apiInstance;
info.onSuccess!(res);
if (props.showSuccessMsg) {
@@ -304,7 +305,8 @@ export function useUpload(
};
onUnmounted(() => {
props.abortOnUnmounted && uploadAbort.abort();
props.abortOnUnmounted && abortList.forEach((abort) => abort());
abortList.length = 0;
});
/**