Upload customRequest 事件
customRequest callback 会返回一个对象
1 | function customRequest(info) { |
我们需要用到 onProgress
和 onSuccess
事件。
一般来说自定义上传方法时,可以添加一个 onProgress
事件
1 | function onProgress({total, loaded}) { |
通过计算 total
和 loaded
可以得出当前进度
然后调用 customRequest
info.onProgress
1 | info.onProgress({ percent: percent }, info.file); |
上传成功后可以在 then
中设置 info.onSuccess
但当设置 fileList
参数时设置进度可能不会生效
这时我们择需要在自定义请求的 onProgress
触发时,重新设置 fileList
,并且为当前上传文件的那一项添加 percent
字段手动设置进度