app.isLogin() // 判断是否登录后 .then(res=>{ this.setData({ login: true }, res2=>{ // 清空临时积分 return app.clearTempScore() // 返回Promise }) }) .then(res => { console.log('.then..............') }) .catch(err=>{ console.log(err) })
1、setData中返回Promise
会直接执行第二个.then(),即使app.clearTempScore返回的状态是pending(正常返回的Promise,状态是pending,不会执行.then())
因为setData是异步请求,并不知道什么时候回调res2,返回Promise
这种情况,等于没有返回Promise
app.isLogin() // 判断是否登录后 .then(res=>{ }) .then(res => { console.log('.then..............') }) .catch(err=>{ console.log(err) })
2、第一个.then()中没有立即返回Promise,代码会顺序执行第二个.then()
3、第一个.then()中立即返回了Promise,代码才会 等待 返回的这个Promise,有了 resolve 或 reject 状态后, 再执行第二个.then()