20 lines
628 B
JavaScript
20 lines
628 B
JavaScript
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();
|
|
|
|
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
|
|
})
|
|
} |