wx-promise-pro
TypeScript icon, indicating that this package has built-in type declarations

3.2.4 • Public • Published

wx-promise-pro

强大、优雅的微信小程序异步库🚀

npm npm Financial Contributors on Open Collective

NPM

优势

  • 方便集成:一处引用,处处使用
  • 把微信小程序所有异步 API promise 化并挂在到wx.pro 对象下
  • 支持 ES2018 finally 特性
  • 支持 TypeScript 开发

安装

你也可以直接把 dist 目录下的 wx-promise-pro.js 拷贝到项目里使用

$ npm i wx-promise-pro -S
# or
$ yarn add wx-promise-pro

初始化

import { promisifyAll, promisify } from 'wx-promise-pro'
// promisify all wx‘s api
promisifyAll()
// promisify single api
promisify(wx.getSystemInfo)().then(console.log)

示例代码

wx.pro.showLoading({
  title: '加载中',
  mask: true
})
wx.pro.request({
  url: 'https://cnodejs.org/api/v1/topics',
  data: {},
  method: 'GET',
  header: {'content-type': 'application/json'}
}).then(res => {
  console.log(res)
}).catch(err => {
  console.log(err)
}).finally(() => {
  wx.pro.hideLoading()
})

Package Sidebar

Install

npm i wx-promise-pro

Weekly Downloads

26

Version

3.2.4

License

MIT

Unpacked Size

787 kB

Total Files

21

Last publish

Collaborators

  • youngjuning