promise then catch 状态改变

2021-06-14  本文已影响0人  RickyWu585

总结

// 同步代码先执行,then里面的是异步函数,后执行
const p1 = Promise.resolve()
console.log('p1',p1)

const p1Then = p1.then(()=>{
  console.log('p1 then')
})

console.log('p1Then:',p1Then)

const p2 = Promise.reject('error')
console.log('p2',p2)
const p2Then = p2.then(()=>{
  console.log('p2 then')
}).catch(err=>{
  console.log(err)
  console.log('p2 catch')
})
console.log('p2Then:',p2Then)

p2Then.then(()=>{
  console.log('p2Then then')
}).catch(()=>{
  console.log('p2Then catch')
})
image.png
image.png
上一篇 下一篇

猜你喜欢

热点阅读