微信小程序 工具库类·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 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)

版权声明:本文由lzhuji.com主机评测所有
文章名称:《微信小程序 工具库类·API Promise化》
文章链接:https://www.lzhuji.com/273051.html
本站资源仅供个人学习交流,请于下载后24小时内删除,不允许用于商业用途,否则法律问题自行承担。

本站不对信息的真伪做任何的保障,请自行甄别,自负责任。

登录

找回密码

注册