Skip to content

Instantly share code, notes, and snippets.

@bcernesto
Last active February 21, 2021 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcernesto/b275ba355a17377dd38ae21d699a5bd0 to your computer and use it in GitHub Desktop.
Save bcernesto/b275ba355a17377dd38ae21d699a5bd0 to your computer and use it in GitHub Desktop.
Ejemplo simple de v-for en tabla HTML con Vue
<!DOCTYPE html>
<html lang="es">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<div id="main">
<h1>{{ title }}</h1>
<table id="tasks">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Title</th>
<th scope="col">Completed</th>
</tr>
</thead>
<tbody>
<tr v-for="tarea in tareas" v-if="!tarea.completed">
<th scope="row">{{ tarea.id }}</th>
<td>{{ tarea.title }}</td>
<td>{{ tarea.completed }}</td>
</tr>
</tbody>
</table>
</div>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script>
$(function(){
main=new Vue({
el: '#main',
data:{
title: 'Listado de tareas pendientes',
tareas: []
}
});
$.get('https://jsonplaceholder.typicode.com/todos', (response) => {
console.log(response);
response.forEach(element => main.tareas.push(element));
$('#tasks').refresh();
}, 'json');
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment