前言
因为业务要求,查了下怎么获取进度,但是资料很分散。虽然又被业务搁置了,还是记录下怎么实现的。
现有代码
前端React
axios向服务器端通信
async post<T>(url: string, body: any): Promise<T>{
return axios
.post(`${this.serverDomain}${url}`), JSON.stringify(body),{
headers: this.headers,
})
.then(
(axiosResponse)=>(
return axiosReponse.data as T;
),
(axiosError)=>(
return axiosError?.reponse?.data || axiosError;
),
);
}
service层的相关方法
async download(ids: number[], locale: string):
Promise<ApiResponse<Blob>> {
const url = `${this.baseUrl}/download?locale=${locale}`;
return this.httpService.post<FileReponse>(url, [...ids]).then(
(response: any) => response