当前位置:网站首页>Promise的使用場景
Promise的使用場景
2022-06-24 08:23: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)
})边栏推荐
- Which is the first poem of Tang Dynasty?
- Serialization of unity
- Introduction to software engineering - Chapter 2 - feasibility study
- pyQt 中 QMenu 响应
- [008] filter the table data row by row, jump out of the for cycle and skip this cycle VBA
- JS scroll div scroll bar to bottom
- Search and recommend those things
- WPS的JS宏实现图片正文在同一段落的分离方法
- Four models of iPhone 13 series have been exposed, and indeed, they are 13 fragrant!
- 将mysql的数据库导出xxx.sql,将xxx.sql文件导入到服务器的mysql中。项目部署。
猜你喜欢

Swift 基础 Swift才有的特性

About the iframe anchor, the anchor is offset up and down, and the anchor has page display problems Srcdoc problem of iframe

李白最经典的20首诗排行榜
![[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

The first exposure of Alibaba cloud's native security panorama behind the only highest level in the whole domain

MAYA重新拓布

Swift Extension ChainLayout(UI的链式布局)(源码)

独立站运营中如何提升客户留存率?客户细分很重要!

WCF TCP protocol transmission

Utilisation de la fermeture / bloc de base SWIFT (source)
随机推荐
VR is destined to reappear in the Jianghu?
You get in Anaconda
Robot acceleration level task priority inverse kinematics
Qopengl display point cloud file
Nodejs redlock notes
对于flex:1的详细解释,flex:1
MAYA重新拓布
小样本故障诊断 - 注意力机制代码 - BiGRU代码解析实现
【毕业季】你好陌生人,这是一封粉色信笺
Introduction to software engineering - Chapter 2 - feasibility study
Écouter le réseau d'extension SWIFT (source)
etcd备份恢复原理详解及踩坑实录
Pagoda panel installation php7.2 installation phalcon3.3.2
Industrial computer anti cracking
Swift Extension ChainLayout(UI的链式布局)(源码)
Optimization and practice of Tencent cloud EMR for cloud native containerization based on yarn
[graduation season] Hello stranger, this is a pink letter
Sql语句内运算问题
11-- longest substring without repeated characters
LINQ query (2)