Página HTML

This commit is contained in:
Joao
2026-06-01 20:56:57 -03:00
parent aee4a1b7fb
commit 50647dd094
3 changed files with 74 additions and 0 deletions
+20
View File
@@ -0,0 +1,20 @@
async function carregarProdutos(){
const resposta = await fetch("http://localhost:5000/produtos");
if (!resposta.ok){
throw new Error("Não foi possível carregar a lista")
}
const produtos = await resposta.json();
let tbody = document.querySelector("tbody");
produtos.forEach(produto => {
let linha = document.createElement("tr");
linha.innerHTML = ` <td>${produto.nome}</td>
<td>${produto.preco}</td>
<td>${produto.estoque}</td>
`
tbody.appendChild(linha);
});
}
window.addEventListener("load", () => {
carregarProdutos();
})