【发布时间】:2018-07-24 07:18:56
【问题描述】:
我正在尝试使用 API 调用另一个函数,在我的 ABC 函数中检查 remaing 是否可用。
如果剩余可用 retun true 否则 return false.below 是我的代码。但我的控制台日志显示 undefined。我想在我的 ABC 函数中将它作为 true 或 false 获取。
export function ABC(data,callback) {
return function (dispatch, getState) {
var res= dispatch(Balance(data));
console.log("Balance status",res)
//rest of code
if(res){
}
................
}
}
export function Balance(data) {
return function (dispatch, getState) {
const url = `api/.../balances`;
axios.post(`${url}`,
data
).then(async function (response) {
if (response.data.remaing > 0) {
return await true;
}else{
return await false;
}
【问题讨论】:
-
我们可以在这里使用promise吗?
-
我建议从你当前的任务中退后一步,学习一些关于 Promise 的初学者教程,以及
async/await。
标签: javascript reactjs async-await react-redux axios