阅读(479) (0)

微信小程序 工具库类·API Promise化

2020-07-27 17:41:34 更新

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 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)