以下axios
调用似乎很好,但是它永远不会返回promise
,但会返回undefined
。
export function getAllSubmissionDetails() {
return (dispatch) => {
axios
.get(`/rbac/members/filledForm/getMain/show/1/data/all`, {
headers: {
'Content-Type': 'application/json',
'Pragma': 'no-cache'
}
})
.then((memResponse) => {
console.log('%%%%%%%');
console.log(memResponse);
if (memResponse.data.status == 200) {
var mem_list = memResponse.data.msg;
if (mem_list.length > 0) {
mem_list = _.sortBy(mem_list, "submissionid").reverse()
dispatch(memIdeaListSuccess(mem_list, null));
return memResponse
} else {
dispatch(memIdeaListFailure("No Submissions", null));
return memResponse
}
} else {
dispatch(memIdeaListFailure(memResponse.data.msg, null));
return memResponse
}
})
.catch((err) => {
dispatch(serviceError(err));
return Promise.reject(error)
});
};
}
答案 0 :(得分:3)
您不会返回axios返回的值,因此不会返回未定义的值
export function getAllSubmissionDetails(){
return (dispatch) => {
// return value here
return axios.get(`/rbac/members/filledForm/getMain/show/1/data/all`, {
headers: { 'Content-Type': 'application/json','Pragma': 'no-cache' }
})
.then((memResponse) => {
console.log('%%%%%%%');
console.log(memResponse);
if(memResponse.data.status == 200){
var mem_list = memResponse.data.msg;
if(mem_list.length>0) {
mem_list = _.sortBy(mem_list,"submissionid").reverse()
dispatch(memIdeaListSuccess(mem_list,null));
return memResponse
} else {
dispatch(memIdeaListFailure("No Submissions",null));
return memResponse
}
}else{
dispatch(memIdeaListFailure(memResponse.data.msg,null));
return memResponse
}
})
.catch((err) => {dispatch(serviceError(err)); return Promise.reject(error)});
};
}