当前位置:网站首页>Promise usage scenarios
Promise usage scenarios
2022-06-24 08:23:00 【Nanjing front end】
1.await && async Keyword waiting for request
async function test(){
var message = await new Promise((resolve,reject)=>{
setTimeout(function(){
resolve("{message:'hello'}")
},3000)
})
.then(value=>{ return JSON.parse(value) })
.then(value=>{
return value
})
console.log(message)
}2. Step by step request
var message = new Promise((resolve,reject)=>{
// Request verification before formal request
setTimeout(function(){
resolve('success')
},3000)
}).then(value=>{
if(value=='success'){// Authentication succeeded
return new Promise((resolve,reject)=>{
setTimeout(function(){
resolve({username:'xx'})
},3000)
})
}
})
message.then(res=>{
console.log(res.username)
})边栏推荐
- WPS的JS宏实现图片正文在同一段落的分离方法
- JVM underlying principle analysis
- Swift 基础 Swift才有的特性
- Utilisation de la fermeture / bloc de base SWIFT (source)
- 2021-03-11 COMP9021第八节课笔记
- Catégorie de prêt 5
- Installation and use of selenium IDE
- "Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
- More than observation | Alibaba cloud observable suite officially released
- JS scroll div scroll bar to bottom
猜你喜欢

2021-03-04 COMP9021第六节课笔记

直播回顾 | 云原生混部系统 Koordinator 架构详解(附完整PPT)

Blue Bridge Cup_ Queen n problem

Solve the problem of notebook keyboard disabling failure

LabVIEW finds prime numbers in an array of n elements

5分钟,客服聊天处理技巧,炉火纯青

李白最经典的20首诗排行榜

Swift 基础 闭包/Block的使用(源码)

12-- merge two ordered linked lists

2022茶艺师(中级)上岗证题库及在线模拟考试
随机推荐
2022年制冷与空调设备运行操作上岗证题库及模拟考试
487. 最大连续1的个数 II ●●
Opening chapter of online document technology - rich text editor
Question 3 - MessageBox pop-up box, modify the default background color
2021-03-16 COMP9021第九节课笔记
[ACNOI2022]做过也不会
Model effect optimization, try a variety of cross validation methods (system operation)
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
The article takes you to understand the security of Windows operating system and protect your computer from infringement
13 -- remove invalid parentheses
2022 mobile crane driver special operation certificate examination question bank and online simulation examination
将mysql的数据库导出xxx.sql,将xxx.sql文件导入到服务器的mysql中。项目部署。
MySQL source and target table row count check
Future trends in automated testing
Pagoda panel installation php7.2 installation phalcon3.3.2
LINQ 查询(2)
贷款五级分类
Transformers pretrainedtokenizer class
[introduction to point cloud dataset]
OC Extension 检测手机是否安装某个App(源码)