작성
·
147
1
<html>
<head>
<title>그랩마켓</title>
<link href="index.css" type="text/css" rel="stylesheet" />
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script src = "https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="header">
<div id="header-area">
<img src="images/icons/logo.png" />
</div>
</div>
<div id="body">
<div id="banner">
<img src="images/banners/banner1.png" />
</div>
<h1>판매되는 상품들</h1>
<div id="product-list"></div>
</div>
<div id="footer"></div>
</body>
<script>
axious
.get(
'https://c3d57b18-f819-4b2f-becf-330ee397bf79.mock.pstmn.io/products'
)
.then(function(result){
console.log('통신 결과 : ', result);
})
.catch(function(error){
console.log('error 발생 : ',error);
});
var products = [
{
name: "농구공",
price: 10000,
seller: "마이클 조던",
imageUrl: "images/products/basketball1.jpeg",
},
{
name: "축구공",
price: 50000,
seller: "호날두",
imageUrl: "images/products/soccerball1.jpg",
},
{
name: "키보드",
price: 15000,
seller: "애플",
imageUrl: "images/products/keyboard1.jpg",
},
];
let productsHtml = "";
for (var i = 0; i < products.length; i++) {
let product = products[i];
productsHtml =
productsHtml +
'<div class="product-card">' +
"<div>" +
'<img class="product-img" src="' +
product.imageUrl +
'" />' +
"</div>" +
'<div class="product-contents">' +
'<span class="product-name">' +
product.name +
"</span>" +
'<span class="product-price">' +
product.price +
"원" +
"</span>" +
'<div class="product-seller">' +
'<img class="product-avatar" src="images/icons/avatar.png" />' +
"<span>" +
product.seller +
"</span>" +
"</div>" +
"</div>" +
"</div>";
}
document.querySelector("#product-list").innerHTML = productsHtml;
</script>
</html>