Skip to content

Commit 191445c

Browse files
committed
tiny update
1 parent 9661386 commit 191445c

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,28 @@ api.getLocation().then((res) => {})
242242

243243
## 特殊API的事件处理
244244
某些 API 既要支持 Promise,又要监听它的事件回调,那么可以采用如下方式:
245+
246+
**以前:**
247+
```javascript
248+
const downloadTask = wx.downloadFile({
249+
url: 'https://example.com/audio/123', // 仅为示例,并非真实的资源
250+
success(res) {
251+
console.log(res)
252+
}
253+
})
254+
255+
downloadTask.onProgressUpdate((res) => {
256+
console.log(res)
257+
})
258+
259+
downloadTask.abort() // 取消下载任务
260+
```
261+
**使用 `mpapi` 之后:**
245262
```javascript
246263
const api = require('mpapi')
247264

248265
const downloadTask = api.downloadFile({
249-
url: 'https://example.com/audio/123', //仅为示例,并非真实的资源
266+
url: 'https://example.com/audio/123', // 仅为示例,并非真实的资源
250267
}).then((res) => {
251268
console.log(res)
252269
})

0 commit comments

Comments
 (0)