We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 9661386 commit 191445cCopy full SHA for 191445c
1 file changed
README.md
@@ -242,11 +242,28 @@ api.getLocation().then((res) => {})
242
243
## 特殊API的事件处理
244
某些 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
257
258
259
+downloadTask.abort() // 取消下载任务
260
+```
261
+**使用 `mpapi` 之后:**
262
```javascript
263
const api = require('mpapi')
264
265
const downloadTask = api.downloadFile({
- url: 'https://example.com/audio/123', //仅为示例,并非真实的资源
266
267
}).then((res) => {
268
console.log(res)
269
})
0 commit comments