Skip to content

Instantly share code, notes, and snippets.

@iagocavalcante
Last active November 14, 2018 02:03
Show Gist options
  • Save iagocavalcante/2db4ca2710d68db5ecca8e422f6dcf29 to your computer and use it in GitHub Desktop.
Save iagocavalcante/2db4ca2710d68db5ecca8e422f6dcf29 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Alunos Front</title>
</head>
<body>
<h1>Lista de alunos estático</h1>
<ul id="alunos">
</ul>
</body>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
<script>
axios.get('http://localhost:3000/api/v1/alunos')
.then(response => criaListaDinamica(response.data))
.catch(error => console.log(error))
const criaListaDinamica = ( alunos ) => {
const ulAlunos = document.getElementById('alunos')
alunos.map(aluno => {
const listaAluno = document.createElement('li')
listaAluno.innerHTML = `Nome: ${aluno.nome}`
ulAlunos.appendChild(listaAluno)
})
}
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment