当前位置:网站首页>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)
})边栏推荐
猜你喜欢

OC extension detects whether an app is installed on the mobile phone (source code)
![3D数学基础[十七] 平方反比定理](/img/59/bef931d96883288766fc94e38e0ace.png)
3D数学基础[十七] 平方反比定理

12-- merge two ordered linked lists

Use of swift basic closure /block (source code)

Future trends in automated testing

Swift foundation features unique to swift

Introduction to software engineering - Chapter 2 - feasibility study

Swift extension chainlayout (UI chain layout) (source code)

jwt(json web token)

Pagoda panel installation php7.2 installation phalcon3.3.2
随机推荐
Interview tutorial - multi thread knowledge sorting
问题4 — DatePicker日期选择器,2个日期选择器(开始、结束日期)的禁用
MySQL source and target table row count check
一文带你了解Windows操作系统安全,保护自己的电脑不受侵害
UTC、GMT、CST
Catégorie de prêt 5
Selenium IDE的安装以及使用
2021-03-11 COMP9021第八节课笔记
LINQ query (2)
Swift 基础 闭包/Block的使用(源码)
Solution of electric education system for intelligent supervision station
5g industrial router Gigabit high speed low delay
You get in Anaconda
OC Extension 检测手机是否安装某个App(源码)
Methods of vector operation and coordinate transformation
2021-03-16 COMP9021第九节课笔记
你还只知道测试金字塔?
12--合并两个有序链表
解决笔记本键盘禁用失败问题
Small sample fault diagnosis - attention mechanism code - Implementation of bigru code parsing