当前位置:网站首页>promise方法的简单使用
promise方法的简单使用
2022-06-29 08:26:00 【swag_特约男演员】
es6的promise会简单的使用,知道使用场景就够日常使用了,这里仅仅只是小笔记,记录resolve和reject的使用

效果:
这里的resolve,reject按字面意思就是成功时走resolve,失败走reject;在resolve,reject添加数据就可以在then回调函数里拿到。需要注意then接受两个函数,第一个是处理resolve的第二个是reject的
// promise方法
testPromise() {
var _Prom = new Promise(function(resolve, reject) {
var num = Math.ceil(Math.random() * 10) //生成1-10的随机数
if (num > 5) {
resolve('大于5走resolve')
} else {
reject('小于5走reject')
}
})
return _Prom
},
test() {
this.testPromise().then(
res => {
console.log(res)
},
err => {
console.log(err)
}
)
}
边栏推荐
- 开发小技巧-图片资源管理
- Did you really make things clear when you were promoted or reported?
- 来个小总结吧
- MySQL row column conversion example
- JS获取图片或base64的宽高等基本信息
- Unity C # e-learning (12) -- protobuf generation protocol
- Wallpaper applet source code double ended wechat Tiktok applet
- Transformer details
- Pointnet/pointnet++ training and testing
- Compare homekit, MI family, and zhiting family cloud edition for what scene based experiences
猜你喜欢

【最全】PS各个版本下载安装及小试牛刀教程(PhotoShop CS3 ~~ PhotoShop 2022)

Differences between x86 and x64
![[untitled]](/img/6e/5dd5dcff89a74f7d367c9186a77268.png)
[untitled]

对比HomeKit、米家,智汀家庭云版有哪些场景化的体验

在 golang 中是如何对 epoll 进行封装的?

npm常用命令

二手交易平台碳减排,有了评估标准

DevOps到底是什么意思?

Enrollment brochure for system integration project management engineer certification in July 2022

La finale de la zone de compétition Hefei de la sixième saison 2022 a été couronnée de succès.
随机推荐
Activemq消息组件发布订阅ReDelivery消息重新投递
[untitled]
Open3D 最远点采样(FPS)
在 golang 中是如何对 epoll 进行封装的?
Wallpaper applet source code double ended wechat Tiktok applet
Verilog size and +: Using
Typescript variable declaration - type assertion
【最全】PS各个版本下载安装及小试牛刀教程(PhotoShop CS3 ~~ PhotoShop 2022)
闭关修炼(二十五)基础web安全
Pointnet/pointnet++ training and testing
P4769-[noi2018] bubble sort [combinatorics, tree array]
io流的总结
Carbon emission reduction of second-hand trading platform, with assessment standards
Core development board & debugger
打印服务IP设置方案
The final of the sixth season of 2022 perfect children's model Hefei division came to a successful conclusion
The @dynamicmemberlookup and callasfunction features in swift implement the object transparent proxy function
Backpack Lecture 9 - detailed understanding and code implementation
Uniapp wechat applet reports an error typeerror: cannot read property 'call' of undefined
晋升或汇报,你真的把事情讲清楚了吗?