2026-06-01 22:28:19 +00:00
|
|
|
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.join();
|
2026-06-01 22:38:31 +00:00
|
|
|
let tbody = document.querySelector("tbody");
|
2026-06-01 22:28:19 +00:00
|
|
|
produtos.forEach(produto =>{
|
|
|
|
|
let linha = document.createElement("tr")
|
|
|
|
|
linha.innerHTML = `
|
|
|
|
|
<td>${produto.nome}</td>
|
|
|
|
|
<td>${produto.preco}</td>
|
|
|
|
|
<td>${produto.estoque}</td>
|
2026-06-01 22:38:31 +00:00
|
|
|
`
|
|
|
|
|
tbody.appendChild(linha);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.addEventListener("load", () => {
|
|
|
|
|
carregarProdutos();
|
|
|
|
|
})
|