当前位置:网站首页>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)
})边栏推荐
- C# Lambda
- 有关iframe锚点,锚点出现上下偏移,锚点出现页面显示问题.iframe的srcdoc问题
- The article takes you to understand the security of Windows operating system and protect your computer from infringement
- 到底哪一首才是唐诗第一?
- Sql语句内运算问题
- Synthesize video through ffmpeg according to m3u8 file of video on the network
- Utilisation de la fermeture / bloc de base SWIFT (source)
- 问题3 — messageBox弹框,修改默认背景色
- Detailed explanation of etcd backup and recovery principle and actual record of stepping on the pit
- Getting started with ffmpeg
猜你喜欢

More appropriate development mode under epidemic situation

RCNN、Fast-RCNN、Faster-RCNN介绍

C language_ Love and hate between string and pointer
![[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA](/img/a0/f03b8d9c8f5e53078c38cce11f8ad3.png)
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA

问题3 — messageBox弹框,修改默认背景色

Swift 基礎 閉包/Block的使用(源碼)

1279_ Vsock installation failure resolution when VMware player installs VMware Tools

Coordinate transformation of graphic technology

C语言_字符串与指针的爱恨情仇

LabVIEW finds prime numbers in an array of n elements
随机推荐
js滚动div滚动条到底部
OC Extension 检测手机是否安装某个App(源码)
Future trends in automated testing
11-- longest substring without repeated characters
Solution of electric education system for intelligent supervision station
Catégorie de prêt 5
487. number of maximum consecutive 1 II ●●
你还只知道测试金字塔?
贷款五级分类
App Startup
软件工程导论——第二章——可行性研究
os.path.join()使用过程中遇到的坑
12-- merge two ordered linked lists
新技术实战,一步步用Activity Results API封装权限申请库
51单片机_外部中断 与 定时/计数器中断
Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
Swift extension networkutil (network monitoring) (source code)
[graduation season] Hello stranger, this is a pink letter
Coordinate transformation of graphic technology
Getting started with ffmpeg