当前位置:网站首页>微信小程序将原生请求通过es6的promise来进行优化
微信小程序将原生请求通过es6的promise来进行优化
2022-04-23 14:10:00 【瑞瑞小同学】
在request文件夹中新建index.js
在需要的page页面进行引入,比如我的首页轮播图数据
代码:index.js
export const request = (params) => {
return new Promise((resolve,reject) => {
wx.request({
...params,
success:(result)=>{
resolve(result)
},
fail:(err)=>{
reject(err)
}
})
})
}
版权声明
本文为[瑞瑞小同学]所创,转载请带上原文链接,感谢
https://blog.csdn.net/yr123456654321/article/details/109034002
边栏推荐
- 帆软中需要设置合计值为0时,一整行都不显示的解决办法
- Date的after时间判断
- Can I compile the header file and source file of the template separately
- postman批量生产body信息(实现批量修改数据)
- 获取线程返回值Future接口与FutureTask类使用介绍
- DP - [noip2000] grid access
- Wechat applet communicates with low-power Bluetooth - sending data to hardware (III)
- Essential difference between restful WebService and gSOAP webservice
- rsync+inotify远程同步
- About the configuration and use of json5 in nodejs
猜你喜欢
微信小程序客服接入,实现发送和接收消息
差分隐私(背景介绍)
帆软中使用if else 进行判断-使用标题条件进行判断
How QT designer adds resource files
KVM学习资源
sql中出现一个变态问题
剑指offer刷题(1)--面向华为
postman批量生产body信息(实现批量修改数据)
Thread group ThreadGroup uses introduction + custom thread factory class to implement threadfactory interface
About the configuration and use of json5 in nodejs
随机推荐
Algorithem_ReverseLinkedList
VMware Workstation 无法连接到虚拟机。系统找不到指定的文件
Oracle-数据泵使用
Wechat applet communicates with low-power Bluetooth - receives data sent by hardware (IV)
json date时间日期格式化
帆软中使用if else 进行判断-使用标题条件进行判断
Five ways of using synchronized to remove clouds and fog are introduced
HyperBDR云容灾V3.3.0版本发布|容灾功能升级,资源组管理功能优化
教育行业云迁移最佳实践:海云捷迅使用HyperMotion云迁移产品为北京某大学实施渐进式迁移,成功率100%
Some experience of using dialogfragment and anti stepping pit experience (getactivity and getdialog are empty, cancelable is invalid, etc.)
帆软中单元格中隔行变色以及数量大于100字体变大变红设置
JSP学习2
How does void * exist?
man man随记和crontab的@reboot用法
Arrays类的使用案例
连接公司跳板机取别名
云迁移的六大场景
关于Jmeter启动闪退问题
正则表达式
win10自带Groove音乐不能播放CUE和APE文件的一种曲线救国办法,自己创建aimppack插件包,AIMP安装DSP插件