Vue単一ページアプリケーションでのPromiseチェーン呼び出しの使用
1295 ワード
eg:
commonLoginFunで:
methods:{
commonLoginFun(){
return xxx.axios.xxxx;//2個return,非同期関数return,非同期関数の戻り値return.
}
}
まとめ:
1.thenメソッドを使用するとpromiseオブジェクトが返され、thenメソッド呼び出しを続行できます.取得したパラメータは、前のthenメソッドreturnの内容です.
2.promiseオブジェクトをパラメータとしてpromiseに渡す.resolve()は直接返されます.
転載先:https://www.cnblogs.com/Neilisme/p/10998048.html
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()は直接返されます.
転載先:https://www.cnblogs.com/Neilisme/p/10998048.html