Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/youngjuning/wx-promise-pro
✨强大、优雅的微信小程序异步库🚀
https://github.com/youngjuning/wx-promise-pro
async await es6 miniapp promise wx-promise wx-promise-pro
Last synced: 5 days ago
JSON representation
✨强大、优雅的微信小程序异步库🚀
- Host: GitHub
- URL: https://github.com/youngjuning/wx-promise-pro
- Owner: youngjuning
- License: mit
- Created: 2018-04-09T16:15:02.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-10-13T02:24:20.000Z (about 3 years ago)
- Last Synced: 2024-05-22T01:11:33.967Z (6 months ago)
- Topics: async, await, es6, miniapp, promise, wx-promise, wx-promise-pro
- Language: JavaScript
- Homepage: https://youngjuning.js.org/wx-promise-pro/
- Size: 474 KB
- Stars: 834
- Watchers: 22
- Forks: 131
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# wx-promise-pro
✨强大、优雅的微信小程序异步库🚀
[![npm](https://img.shields.io/npm/v/wx-promise-pro.svg)](https://www.npmjs.com/package/wx-promise-pro) [![npm](https://img.shields.io/npm/dt/wx-promise-pro.svg)](https://www.npmjs.com/package/wx-promise-pro) [![Financial Contributors on Open Collective](https://opencollective.com/wx-promise-pro/all/badge.svg?label=financial+contributors)](https://opencollective.com/wx-promise-pro)
[![NPM](https://nodei.co/npm/wx-promise-pro.png?compact=true)](https://nodei.co/npm/wx-promise-pro/)
## 优势
- 方便集成:一处引用,处处使用
- 把微信小程序所有异步 API promise 化并挂在到`wx.pro` 对象下
- 支持 ES2018 `finally` 特性
- 支持 TypeScript 开发## 安装
> 你也可以直接把 `dist` 目录下的 `wx-promise-pro.js` 拷贝到项目里使用
```bash
$ npm i wx-promise-pro -S
# or
$ yarn add wx-promise-pro
```## 初始化
```js
import { promisifyAll, promisify } from 'wx-promise-pro'
// promisify all wx‘s api
promisifyAll()
// promisify single api
promisify(wx.getSystemInfo)().then(console.log)
```## 示例代码
```js
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()
})
```## 已知问题
- `createSignal`、`lanDebug` 可能会引发报错,所以并没有挂载到 `wx.pro` 对象上。