레스토랑 예약 사이트 만들기 3

<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div id="app">Hello, world!</div>

<script src="./src/index.js"></script>
</body>
</html>
(async () => {
const url = "http://localhost:8080/restaurants";
const response = await fetch(url);
const restaurants = await response.json();
console.log(restaurants);

const element = document.getElementById('app');
element.innerHTML = JSON.stringify(restaurants);

})();
(async () => {
const url = "http://localhost:8080/restaurants";
const response = await fetch(url);
const restaurants = await response.json();
console.log(restaurants);

const element = document.getElementById('app');
element.innerHTML = `
${restaurants[0].id}
${restaurants[0].name}
`

})();
(async () => {
const url = "http://localhost:8080/restaurants";
const response = await fetch(url);
const restaurants = await response.json();
console.log(restaurants);

const element = document.getElementById('app');
element.innerHTML = `
${restaurants.map(restaurant => `
<p>
${restaurant.id}
${restaurant.name}
${restaurant.address}
</p>
`).join('')}
`;

})();
Share