当前位置:网站首页>Promise的使用场景
Promise的使用场景
2022-06-24 06:58:00 【南京前端】
1.await && async 关键字等待请求
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.分步请求
var message = new Promise((resolve,reject)=>{
//正式请求前先请求验证
setTimeout(function(){
resolve('success')
},3000)
}).then(value=>{
if(value=='success'){//身份验证成功
return new Promise((resolve,reject)=>{
setTimeout(function(){
resolve({username:'xx'})
},3000)
})
}
})
message.then(res=>{
console.log(res.username)
})边栏推荐
- Vscode topic recommendation
- pyQt 中 QMenu 响应
- Simple refraction effect
- Model effect optimization, try a variety of cross validation methods (system operation)
- JDBC 在性能测试中的应用
- Teach you how to use the reflect package to parse the structure of go - step 1: parameter type check
- 51单片机_外部中断 与 定时/计数器中断
- C# Lambda
- OpenCV get(propId) 常用的值
- June 27, 2021: given a positive array arr, it represents the weight of several people
猜你喜欢

WCF TCP protocol transmission

PAT 1157:校庆

Swift extension networkutil (network monitoring) (source code)

有关iframe锚点,锚点出现上下偏移,锚点出现页面显示问题.iframe的srcdoc问题

Swift Extension NetworkUtil(網絡監聽)(源碼)

权限模型 DAC ACL RBAC ABAC

Utilisation de la fermeture / bloc de base SWIFT (source)

io模型初探

C language_ Love and hate between string and pointer

OC extension detects whether an app is installed on the mobile phone (source code)
随机推荐
C# Lambda
[ACNOI2022]做过也不会
Getting started with crawler to giving up 06: crawler play Fund (with code)
到底哪一首才是唐诗第一?
问题3 — messageBox弹框,修改默认背景色
"Adobe international certification" about Adobe Photoshop, creating and modifying brush tutorials?
longhorn安装与使用
RCNN、Fast-RCNN、Faster-RCNN介绍
工控机防破解
Pipeline concept of graphic technology
李白最经典的20首诗排行榜
Analysis of abnormal problems in domain name resolution in kubernetes
Application of JDBC in performance test
基金的募集,交易与登记
12-- merge two ordered linked lists
Teach you how to use the reflect package to parse the structure of go - step 1: parameter type check
Atguigu---16-custom instruction
[008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
13 -- remove invalid parentheses
487. number of maximum consecutive 1 II ●●