• 优雅地解决异步操作
  1. new Promise((resolve, reject) => {
  2. setTimeout(() => {
  3. resolve('hello')
  4. }, 1000)
  5. }).then(data => {
  6. console.log(data);
  7. }).catch(err => {
  8. console.log(err);
  9. })
  • 链式编程
  • 三种状态
  1. pending
  2. fullfill-then
  3. reject-catch

    链式调用

    promise:all

某个需求需要两次请求,进行包装