【发布时间】:2020-07-09 07:28:44
【问题描述】:
不知道这是否是个好问题,因为我是 JavaScript 的初学者,但我想在 fetch api 中使用解构得到错误:
Uncaught (in promise) TypeError: response is not iterable
问题出在哪里,解决问题的好方法是什么?如果可能的话,你可以用 response.json 写两个版本,一个不写。提前致谢。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<style>
</style>
</head>
<body>
<script>
fetch("https://o", {
method: "GET",
headers: {
"Content-type": "application/json",
"X-API-Key": "***"
}
})
.then((response) => {
// response.json().then(function(json) {
const [b] = response
//console.log(json)
console.log(b)
});
// })
</script>
</body>
</html>
【问题讨论】:
标签: javascript html arrays fetch fetch-api