摘要:本文将带你了解微信小程序开发之 wx.request 方法的异步封装。,希望本文对大家学微信有所帮助。
本文将带你了解微信小程序开发之 wx.request 方法的异步封装。,希望本文对大家学微信有所帮助。
wx-promise-request 是对微信小程序 wx.request 方法的异步封装。解决问题支持 Promise (使用 es6-promise 库)。管理请求队列,解决 request 最大并发数超过 10 会报错的问题。下载npm install wx-promise-request然后拷贝 dist/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,如:使用 qcloud 提供的 request 方法;使用其他 Promise 库等等。import {request, setConfig} from './wx-promise-request';
import qcloud from './vendor/qcloud-weapp-client-sdk/index';
import Promise from 'bluebird';
setConfig({
request: qcloud.request,
Promise,
})
request({
url: 'test.php',
})
.then(res => console.log(res))
.catch(error => console.log(error));LicenseMIT
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注职坐标移动开发之微信频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号