【发布时间】:2021-03-14 15:51:10
【问题描述】:
我正在获取待办事项列表,我想知道为什么当我这样做时它会给我undefined
.then((response) => {
response.json();
}
它适用于
.then(response => response.json())
为什么会这样?
另外,当我获取数据时,它们是对象,我将它们保存在数组中
completed: true,
id: 199,
title: "numquam repellendus a magnam",
userId: 10
},
等等。
现在,我有 html 模板,我想将它加载到我的样式所在的 html 中,我该怎么做?
<div class="card">
<p>//Want Id here</p>
<strong>// Want Title here</strong>
</div>
获取代码:
let todos = [];
function fetchData() {
fetch('https://jsonplaceholder.typicode.com/todos').then(response => response.json())
.then((json) => {
todos = json;
console.log(todos);
})
}
fetchData();
【问题讨论】:
标签: javascript fetch-api