작성
·
333
0
코드가 잘못 됐나요..
상품 목록이 나오질 않네요..
#1 vsCode
<html>
<head>
<title>TerretAccompany</title>
<link href="index.css" type="text/css" rel="stylesheet" />
<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>
axios
.get("https://2007f5d2-9d8b-49f0-8b70-032507e17d79.mock.pstmn.io")
.then(function (result) {
console.log("통신 결과 : ", result);
const products = result.data.products;
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">' +
"<!-- text를 넣을때 많이 씀 -->" +
'<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;
})
.catch(function (error) {
console.error("error 발생 : ", error);
});
</script>
</html>
#2 postman
{
"products" : [
{ "name": "농구공", "price": 500000, "seller": "조던", "imageUrl": "images/products/basketball1.jpeg" },
{ "name": "축구공", "price": 600000, "seller": "메시", "imageUrl": "images/products/soccerball1.jpg" },
{ "name": "키보드", "price": 300000, "seller": "그랩", "imageUrl": "images/products/keyboard1.jpg" }
]
}
답변 1
0
script의 axios.get 코드를 봤을 때 products가 경로에 빠져있네요! 아래 url로 변경하고 다시 해보시겠어요?
https://2007f5d2-9d8b-49f0-8b70-032507e17d79.mock.pstmn.io/products