惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
腾讯CDC
The Cloudflare Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
D
Docker
W
WeLiveSecurity
L
LINUX DO - 最新话题
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Hugging Face - Blog
Hugging Face - Blog
Recent Announcements
Recent Announcements
Application and Cybersecurity Blog
Application and Cybersecurity Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
Secure Thoughts
The Last Watchdog
The Last Watchdog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Y
Y Combinator Blog
月光博客
月光博客
N
News | PayPal Newsroom
WordPress大学
WordPress大学
Webroot Blog
Webroot Blog
Cloudbric
Cloudbric
F
Full Disclosure
有赞技术团队
有赞技术团队
Security Archives - TechRepublic
Security Archives - TechRepublic
T
Tailwind CSS Blog
D
DataBreaches.Net
T
The Blog of Author Tim Ferriss
P
Privacy & Cybersecurity Law Blog
H
Hacker News: Front Page
T
Troy Hunt's Blog
SecWiki News
SecWiki News
美团技术团队
博客园 - 司徒正美
S
Schneier on Security
P
Palo Alto Networks Blog
宝玉的分享
宝玉的分享
Attack and Defense Labs
Attack and Defense Labs
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
PCI Perspectives
PCI Perspectives
Cyberwarzone
Cyberwarzone
MongoDB | Blog
MongoDB | Blog
B
Blog RSS Feed
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
IT之家
IT之家
V2EX - 技术
V2EX - 技术
Vercel News
Vercel News
C
CERT Recently Published Vulnerability Notes

博客园 - jowo

websql操作类封装 Vue.js中Promise、异步、同步、定时器 async/await 来处理异步详解 使用富文本编辑器wangEditor3 zTree setting 配置 WebSQL vue-cli快速构建项目 接收的第一个参数是模块的局部状态对象。 如何使用JavaScript检测Ctrl+V,Ctrl+C? 什么情况下我应该使用 Vuex? Vue+node.js实现一个简洁的个人博客系统 Vuex 是什么? vue中mixins的理解及应用 Vue:slot用法 web.xml文件的的param-name Robots协议一定放在网站根目录下 浅谈重写与重载 笔记纪要:C# WebService URL重写 Java应用监控利器JMX
Promise的基本用法
jowo · 2020-05-11 · via 博客园 - jowo
1.Promise是什么?

Promise是异步编程的一种解决方案,在ES6中Promise被列为了正式规范,统一了用法,原生提供了Promise对象。

Promise打印出来的详细信息

2.Promise的基本用法
  • then中成功失败的执行
// resolve代表成功 reject失败 都是一个函数

let p = new Promise(function(reslove,reject){

    //reslove('成功')  //状态由等待变为成功,传的参数作为then函数中成功函数的实参

    reject('失败')  //状态由等待变为失败,传的参数作为then函数中失败函数的实参

})

//then中有2个参数,第一个参数是状态变为成功后应该执行的回调函数,第二个参数是状态变为失败后应该执行的回调函数。

p.then((data)=>{

    console.log('成功'+data)

},(err)=>{

    console.log('失败'+err)

})
Promise承诺:默认情况下是等待状态pending,如果有一天状态转变为成功就成功了,如果状态变成失败就失败了。状态一旦改变了就不能再改变了。

  • 如果then中返回了一个promise 会将promise的结果继续传给第二then中(如果结果是将状态改成成功就走下一个then的成功回调,状态改为失败就走下一个then的失败回调)

作者:新叶子
链接:https://www.jianshu.com/p/3023a9372e5f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。