fetch使用中遇到过这个错误TypeError: Failed to execute 'json' on 'Response': body stream is locked,后来发现它与Response响应状态无关,真正的问题是您只能使用Response.json()一次,如果您多次使用它,就会发生错误。
fetch('http://localhost:3000/movies').then(response =>{
console.log(response);
if(response.ok){
console.log(response.json()); //first consume it in console.log
return response.json(); //then consume it again, the error happens
}
因此,解决方案是避免在then块中多次使用Response.json()。把上面的两个console.log语句去掉就可以了,我也是打了console.log才出现这种低级错误