摘要:本文将带你了解解决微信小程序开发之 请求的并发数限制,希望本文对大家学微信有所帮助
本文将带你了解解决微信小程序开发之 请求的并发数限制,希望本文对大家学微信有所帮助
wx-promise-request 是微信小程序 wx.request 方法的不支持 Promise 和并发数问题的解决方案。如果只需要解决并发数问题,可以使用我的 wx-queue-request解决问题支持 Promise (使用 es6-promise 库)。管理请求队列,解决 request 最大并发数超过 10 会报错的问题。下载由于小程序不支持 npm,所以直接右键保存 index.js 文件即可。使用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))APIsetConfig(object)可以通过 setConfig 配置 wx-promise-request 的行为。属性说明类型默认值request发起网络请求的函数Functionwx.requestPromisePromise 函数Functiones6-promiseconcurrency最大并发数number10import {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));
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号