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是异步请求,会拿到 临时储物台 执行,此时,流水线上并没有 返回 Promise

   所以,会顺序执行流水线上的第二个.then()

app.isLogin()
// 判断是否登录后
.then(res=>{ })
.then(res => {
console.log('.then..............')
})
.catch(err=>{
console.log(err)
})

2、第一个.then()中没有直接的 return 一个Promise,代码会顺序执行第二个.then()

3、第一个.then()中如果有直接的 return 一个Promise(流水线上return了一个Promise),代码才会 等待 return 的这个Promise,有了 resolve 或 reject 状态后, 再执行第二个.then()

4、如果Promise内部出错,并且内部reject了错误(如果没有reject错误,会直接报错),则这个Promise会寻找距离他最近的.catch()方法执行

   如果Promise内部没有出错,则这个Promise会寻找距离他最近的.then()方法执行

   如果app.isLogin()内部出错,并且内部reject了错误(如果没有reject错误,会直接报错),会执行距离他最近的(也就是最下边那个).catch()方法

   如果app.isLogin()内部没有出错,会执行距离他最近的(紧挨着他的那个).then()方法

onLookPhone(){
app.isLogin()
.then(res=>{
return app.clearTempScore()
})
.then(res=>{
return app.getUserScore()
})
.then(res=>{
console.log('.then3')
})
.catch(err=>{
console.log(err)
})
},

多个Promise执行顺序的更多相关文章

  1. js 关于setTimeout和Promise执行顺序问题

    js 关于setTimeout和Promise执行顺序问题 异步 -- Promise和setTimeout 执行顺序   Promise 和 setTimeout 到底谁先执行 定时器的介绍 Jav ...

  2. js,timeout,promise执行顺序

    总结 macro-task包括:script(整体代码), setTimeout, setInterval, setImmediate, I/O, UI rendering. micro-task包括 ...

  3. 宏任务和微任务:setTimeout和Promise执行顺序

    先以一道面试题做引子: 写出这段程序的输出内容: setTimeout(function(){ console.log(); },); new Promise(function(a,b){ conso ...

  4. 关于setTimeout和Promise执行顺序问题

    先看一段代码 console.log('打印'+1); setTimeout(function(){ console.log('打印'+2); }) new Promise(function(reso ...

  5. Promise 执行顺序

    加深印象 setTimeout(function() { console.log("timeout-start"); }, 200) // 改为100呢 console.log(& ...

  6. Promise对象及它在js中的执行顺序

    关于Promise对象的学习及它的执行顺序 学习阮一峰老师的ES6入门后的记录 1.promise的定义 promise是一个对象,通常包裹着一个异步操作,promise对象提供一些接口的方法,返回一 ...

  7. Promise和setTimeout执行顺序 面试题

    看到过下面这样一道题: (function test() { setTimeout(function() {console.log(4)}, 0); new Promise(function exec ...

  8. promise.then, setTimeout,await执行顺序问题

    promise.then VS setTimeout 在chrome和node环境环境中均输出2, 3, 1, 先输出2没什么好说的,3和1顺序让人有些意外 原因: 有一个事件循环,但是任务队列可以有 ...

  9. 8张图让你一步步看清 async/await 和 promise 的执行顺序

    摘要: 面试必问 原文:8张图帮你一步步看清 async/await 和 promise 的执行顺序 作者:ziwei3749 Fundebug经授权转载,版权归原作者所有. 为什么写这篇文章? 说实 ...

随机推荐

  1. VUE 1.0

    现代开发模式:vue/react. 20%的时间花在了表现层 传统开发模式:jquery. 80%的时间花在了表现层 MVC——数据.表现.行为分离 视图层(表现层)<----->数据层 ...

  2. [bzoj1135][Ceoi2011]Match_线段树

    [Ceoi2011]Match 题目大意:初始时滑冰俱乐部有1到n号的溜冰鞋各k双.已知x号脚的人可以穿x到x+d的溜冰鞋. 有m次操作,每次包含两个数ri,xi代表来了xi个ri号脚的人.xi为负, ...

  3. /tmp/orbit-oracle/目录inode耗尽

    [root@iZ25zpeock2Z orbit-oracle]# cd /[root@iZ25zpeock2Z /]# du -cks * |sort -nr|head -n 20du: canno ...

  4. sql常用到的查询连接

    一.内连接(Inner Join) select * from a inner join b on a.name=b.name; 此语句的结果为同时匹配表a和表b的记录集.即内连接取的是两个表的交集. ...

  5. ARC100E. Or Plus Max

    题目 好题.没想出解法. 官方题解: 这个解法和 Small Multiple 那道题的解法有异曲同工之妙. 扩展 若把 $\mathsf{or}$ 改成 $\mathsf{and}$ 或者 $\ma ...

  6. COleVariant功能

    COLeVariant是数据库常用到的数据类型.它可以是字符串,整型值,日期等.知道怎样将它转换为CString. COLeVariant类是对VARIANT结构的封装.它的构造函数具有极为强大的功能 ...

  7. GCD and LCM HDU - 4497(质因数分解)

    Problem Description Given two positive integers G and L, could you tell me how many solutions of (x, ...

  8. Java实现的基础数据结构

    Java实现的基础数据结构 0,常用的基础数据结构 图1 基础数据结构&相关特性 图2 Java自带的类集框架&继承关系图 1,数组[Array] 特点:长度固定.查找方便[直接使用i ...

  9. C#选择文件保存路劲

    private void button8_Click(object sender, EventArgs e) { FolderBrowserDialog dialog = new FolderBrow ...

  10. 从零开始搭建react应用

    用create-react-app搭建react应用,了解npm run start的工作过程. 第一步:安装脚手架 create-react-app 1. 在node里 npm install cr ...