[英]Why isn't my function reaching this point?
我被困了一個小時試圖解決這個問題。 我有一個現在看起來像的功能
myfunction()
{
console.log("myfunction called");//TEST
Axios.post('someurl/' + id)
.then(response =>
{
console.log("We're in the .then ...");//TEST
onGoodRequest(response.data, response);
})
.catch(response =>
{
console.log("We're in the .catch ...");//TEST
this.setState({ curUploadState: uploadStates.SHOWSTOPPER });
});
console.log("We're here now ...");//TEST
}
我在我的React組件中調用它,由於某種原因它被卡住了。 控制台中沒有JavaScript錯誤,我唯一看到的是
myfunction called
那么可能發生了什么? 我什至做到了
var x = Axios.post('someurl/' + id)
.then(response =>
{
console.log("We're in the .then ...");
onGoodRequest(response.data, response);
})
.catch(response =>
{
console.log("We're in the .catch ...");
this.setState({ curUploadState: uploadStates.SHOWSTOPPER });
});
console.log(x);
console.log("We're here now ...");
沒有任何記錄。
您似乎沒有返回任何內容,因為箭頭功能位於花括號上方的行中。 將花括號向上移動一行:
myfunction()
{
console.log("myfunction called");//TEST
Axios.post('someurl/' + id)
.then(response => {
console.log("We're in the .then ...");//TEST
onGoodRequest(response.data, response);
})
.catch(response => {
console.log("We're in the .catch ...");//TEST
this.setState({ curUploadState: uploadStates.SHOWSTOPPER });
});
console.log("We're here now ...");//TEST
}
=>
基本上是隱式返回。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.