当我按下按钮时,我得到未定义的返回值。
<Button btnType="outline" onClick={LockUnlockAccountHandler}>
lock client’s account
</Button>
const LockUnlockAccountHandler = async () => {
const status = await LockUnlockAccount(detailData?.userId, detailData?.blocked ? 'UNLOCK' : 'LOCK');
console.log(status)
if(status){
setDetailData({
...detailData,
blocked: !detailData.blocked
})
}
}
上面的函数中未定义状态值,下面的函数应该为 true 或 false。
export async function LockUnlockAccount(clientID, dataVal) {
var config = {
method: 'post',
url: endpoint.lockAccount + clientID + "/status" + endpoint.key,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
data : qs.stringify({
'status': dataVal
})
};
axios(config)
.then(function (response) {
//console.log(JSON.stringify(response));
if (response.status === 200) {
toast('succès');
return true;
}
return false;
})
.catch(function (error) {
console.log(error);
toast('error');
return false;
});
}
最佳答案
您没有从 LockUnlockAccount
返回任何内容
你需要做
return axios(config).then(...)
关于javascript - 未从异步等待函数获取返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65885806/