更新时间:2022-12-29 GMT+08:00
支持取消下载文件
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| url | String | 是 | 下载资源的url提示:URL中如果包含中文或者特殊字符,请使用encodeURIComponent进行处理 |
| headers | Object | 否 | Object HTTP 请求 Header |
| filePath | String | 是 | 文件存放到本地的地址,包含文件名称及后缀(/download/test.png) |
| progress | Number | 否 | 是否返回下载进度。1:返回,0:不返回。默认为 0 |
| onProgress | Function | 否 | 当progress为1时,必填。回调函数,持续回调 |
| onSuccess | Function | 否 | 下载成功后回调函数 |
| onError | Function | 否 | 下载失败或是异常的回调函数 |
返回说明
| 参数 | 类型 | 说明 |
|---|---|---|
| abort | Function | 取消下载函数 |
- ES6版本
const downloadTask = await HWH5.downloadFileOperation({ url: '', headers: {}, filePath: '', progress: 1, onProgress: _data => console.log('进度', _data), onSuccess: res => console.log('--------- success', res), onError: err => console.log('--------- error', err) }); downloadTask.abort(); //取消下载
- ES5版本
HWH5.downloadFileOperation({ url: '', headers: {}, filePath: '', progress: 1, onProgress: function (_data) { console.log('进度', _data); }, onSuccess: function (res) { console.log('--------- success', res); }, onError: function (err) { console.log('--------- error', err); } }).then(function (result) { downloadTask.abort(); //取消下载
父主题: 上传文件