Reread a response body from JavaScript's fetch

前端 未结 3 872
故里飘歌
故里飘歌 2021-01-03 22:53

fetch() returns promise which (if successful) resolves to a Response object. A very common thing to do is immediately call Response.json() to convert the respon

3条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-03 23:22

    Assigning the response.json() to a variable and returning it worked for me. clone() was again saying its locked.

    fetch("http://localhost:3000/watchlist")
        .then(response => {
          var res = response.json();
          return res;
        })
        .then(data => {
          console.log(data);
          this.setState({ data });
        });
    

提交回复
热议问题