<script>
let todoList = [];
async function getTodos(){
const url = 'https://jsonplaceholder.typicode.com/todos/';
const res = await fetch(url);
let resData = res.json();
if(res.ok){
console.log(resData);
return resData;
} else {
throw new Error("error");
}
}
</script>
<div>
<button on:click={() => todoList = getTodos()}>
todoList 가져오기
</button>
{#await todoList}
<p>
loading
</p>
{:then items}
<ul>
{#each items as item}
<li>{item.id}. {item.title}</li>
{/each}
</ul>
{:catch error}
<p style="color: red">
{error.message}
</p>
{/await}
</div>