# DownloadTask.onProgressUpdate(function listener)
监听下载进度变化事件。
# 支持情况
| 项 | 说明 |
|---|---|
| 兼容性 | 兼容微信 |
# 语法
downloadTask.onProgressUpdate(function listener)
# 参数
function listener
| 参数 | 类型 | 说明 |
|---|---|---|
| progress | number | 下载进度百分比,范围 0–100 |
| totalBytesWritten | number | 已下载的数据量,单位 KB |
| totalBytesExpectedToWrite | number | 预期需下载的数据总量,单位 KB |
# 返回值
void。
# 示例代码
const task = mt.downloadFile({
url: 'https://example.com/file.zip',
success(res) { console.log(res.tempFilePath) }
})
task.onProgressUpdate((res) => {
console.log('进度:', res.progress)
console.log('已下载:', res.totalBytesWritten, 'KB')
console.log('总大小:', res.totalBytesExpectedToWrite, 'KB')
})
# 与微信差异
无差异(行为与微信小游戏一致)。