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