wx promise request
支持自定并发数功能
wx-promise-request is a solution to the problem of WeChat applet wx.request
method not supporting Promise and concurrency. If you only need to solve the problem of concurrency, you can use my wx-queue-request
Can be downloaded using npm
$ npm i wx-promise-request
You can also right-click to save the index.js file.
import { request } from './wx-promise-request' ;
request ( {
url : 'test.php' ,
data : {
x : '' ,
y : '' ,
} ,
header : {
'content-type' : 'application/json' ,
} ,
} )
. then ( res => console . log ( res ) )
. catch ( error => console . error ( error ) )
setConfig(object)
The behavior of wx-promise-request can be configured through setConfig.
property | illustrate | type | default value |
---|---|---|---|
request | Function to initiate network request | Function | wx.request |
Promise | Promise function | Function | es6-promise |
concurrency | Maximum number of concurrencies | number | 10 |
import { request , setConfig } from './wx-promise-request' ;
import qcloud from './vendor/qcloud-weapp-client-sdk/index' ;
import Promise from 'bluebird' ;
// 根据自身需求,来定制 request
setConfig ( {
request : qcloud . request , // 使用 qcloud 提供的请求方法
Promise , // 使用 bluebird 作为 Promise
concurrency : 5 , // 限制最大并发数为 5
} )
request ( {
url : 'test.php' ,
} )
. then ( res => console . log ( res ) )
. catch ( error => console . log ( error ) ) ;
MIT