- API Promise化
- 安装
- 使用
API Promise化
扩展微信小程序api支持promise
安装
npm install --save miniprogram-api-promise
使用
在小程序入口(app.js)调用一次promisifyAll,只需要调用一次。
示例:
import { promisifyAll, promisify } from 'miniprogram-api-promise';const wxp = {}// promisify all wx's apipromisifyAll(wx, wxp)console.log(wxp.getSystemInfoSync())wxp.getSystemInfo().then(console.log)wxp.showModal().then(wxp.openSetting())// compatible usagewxp.getSystemInfo({success(res) {console.log(res)}})// promisify single apipromisify(wx.getSystemInfo)().then(console.log)
