promise方法详解

1.什么是promise

image.png


2.什么是回调地狱

image.png

image.png


●回调地狱,其实就是回调函数嵌套过多导致的。
3.promise基本使用
promise 就是一个es6语法 当我们new一个promise,此时我们需要传递一个回调函数,这个函数为立即执行的,称之为(executor)
这个回调函数,我们需要传入两个参数 reslove reject
当执行了reslove函数,会回调promise对象的.then函数 .then函数既能接收成功也
能接收失败
当执行了reject函数,会回调promise对象的.catche函数

image.png


4.promise 三种状态

image.png

image.png


5.promise result
请求成功或失败后返回的结果

image.png


6.promise resolve方法

image.png


7.promise reject方法

image.png


8.promise.all方法

image.png

image.png


9.promise.race方法

image.png


10.promise.allSettled方法

image.png


11.promise.any

image.png

---------------------完结撒花!!! 若有收获就点个赞吧!!

猜你喜欢

转载自blog.csdn.net/m0_61043829/article/details/131912180
今日推荐