promise

    var axios = new Promise((resolve, reject) => {
        if(1==1){
            resolve("成功")
        }else{
            reject('失败')
        }
    })

    axios.then(res => {
        console.log(res);
    }).then(res => {
        console.log(res);
    })

promise相当于一个状态机

promise的三种状态

  • pending
  • fulfilled
  • rejected

1.promise 对象初始化状态为 pending
2.当调用resolve(成功),会由pending => fulfilled
3.当调用reject(失败),会由pending => rejected

posted @ 2021-10-28 21:07  从入门到入土  阅读(34)  评论(0编辑  收藏  举报