React Fetch返回未定义,但在控制台中它返回响应

时间:2019-03-13 12:08:45

标签: reactjs post fetch

我可以在第一个控制台中看到我的回复,但是始终为undefined

fetch("/api/v1/legacy/tenant-shop", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify(dataToSubmit)
})
  .then(response =>
    console.log("THIS RESPONSE IS WORKING, IT CONSOLE 201", response.status)
  )
  .then(response => {
    if (response && response.status === 201) {
      console.log("BUT IT NEVER GOES THERE");
      this.props.router.push("/congratilations");
    } else {
      console.log("THE RESULT OF THIS CONSOLE IS NULL", response && response);
    }
  });

1 个答案:

答案 0 :(得分:5)

您不会从前一个git-review返回任何内容,因此下一个.then()不会得到任何有用的值。

尝试

.then()