标签:resolve fun class eject err info document catch pre
let checkLogin = function () { return new Promise(function (resolve, reject) { let flag = document.cookie.indexOf(‘userId‘)>-1?true:false; if(!flag){ console.log(flag) resolve({ status:0, result:true }) }else { reject(‘error000‘); } }) }; let getUserInfo = () => { return new Promise((resolve,reject)=>{ let userInfo = { userId:‘101‘ }; resolve({userInfo}); }); } checkLogin().then(function (res) { if(res.status==0){ console.log(‘login succsess‘); return getUserInfo(); } }).catch((error)=>{ console.log(`errors:${error}`); }).then((res2)=>{ console.log(`userId:${res2.userInfo.userId}`) }).catch((error)=>{ }) Promise.all([checkLogin(),getUserInfo()]).then(([res1,res2])=>{ console.log(`result1:${res1.result},reult2:${res2.userInfo.userId}`); })
标签:resolve fun class eject err info document catch pre
原文地址:http://www.cnblogs.com/zhoujx1066/p/7765682.html