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()会被直接返回。

 

相关文章:

  • 2021-07-11
  • 2022-03-02
  • 2023-03-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2021-07-10
相关资源
相似解决方案