小程序 API 进行Promise化
-
安装
miniprogram-api-promise@1.0.4
npm install --save miniprogram-api-promise@1.0.4yarn add miniprogram-api-promise@1.0.4
-
在
app.js
中调用promisifyAll()
方法。// 实现异步 API Promise 化 import { promisifyAll } from 'miniprogram-api-promise'const wxp = wx.p = {} promisifyAll(wx,wxp)
-
调用接口
async getShopData() {const { data:shopList } = await wx.p.request({url: `https://applet-base-api-t.itheima.net/categories/${this.data.query.id}/shops`,method: "GET",data: {_page: this.data.page,_pageSize: this.data.pageSize},})this.setData({ shopList }) },