1 回答
TA贡献1862条经验 获得超6个赞
多亏了拉贾贾加纳坦邦,我错过了等待公理().then行的返回,所以完整的工作代码在下面。我还更新了上面的JS小提琴。
async function axios() { // emulate axios returning a promise
return new Promise((resolve, reject) => {
resolve('return from axios');
})
}
// authentication layer. check for 401 and use Promise.reject
async function api() {
return axios().then(
response => {
// if ( response.status==401 )
// Promise.reject(response.status)
console.log('api then: '+response)
return Promise.resolve(response+'~return from api');
})
}
// services layer builds query params etc...
async function getMails() {
return api();
}
// vuex store to handle emails
// here just run js
getMails().then( function(response){
console.log('back from getMails with:'+response);
let mails = response;
console.log('mails: '+mails);
})
添加回答
举报