扩展微信小程序api支持promise
npm install --save miniprogram-api-promise
在小程序入口(app.js)调用一次promisifyAll,只需要调用一次。
示例:
import { promisifyAll, promisify } from 'miniprogram-api-promise';
const wxp = {}
// promisify all wx's api
promisifyAll(wx, wxp)
console.log(wxp.getSystemInfoSync())
wxp.getSystemInfo().then(console.log)
wxp.showModal().then(wxp.openSetting())
// compatible usage
wxp.getSystemInfo({success(res) {console.log(res)}})
// promisify single api
promisify(wx.getSystemInfo)().then(console.log)
(c) 2024 chaojicainiao.com MIT license