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