首页 > 其他 > 详细

在Vue单页面应用中使用Promise链式调用

时间:2019-06-10 16:38:45      阅读:181      评论:0      收藏:0      [点我收藏+]

eg:

  this.commonLoginFun().then((res) => {
      if (res.errNo === 0) {
        const { isLogin } = res.data;
        if (isLogin) {
          this.isLogin = true;
          this.userPhone = res.data.phone;
        } else {
          this.isLogin = false;
        }
      }
    });

在commonLoginFun中:

methods:{

  commonLoginFun(){

    return xxx.axios.xxxx;  //2个return,把异步函数return,把异步函数的返回值return。 

  }

}

总结:

1. 使用then方法之后会返回一个promise对象,可以继续使用then方法调用,再次调用所获得的参数是上个then方法return的内容。

2. 将一个promise对象当做参数传递给promise.resolve()会被直接返回。

 

在Vue单页面应用中使用Promise链式调用

原文:https://www.cnblogs.com/Neilisme/p/10998048.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!