I am trying to learn and make a very simple agenda in VUE.js. I was able to list the users by traversing them with Axios. What I would like to implement now, is to click on a user, in the middle column (More info) bring me your email, phone, address.
But I do not know how to start ...
Here the codes ...
<div id="app">
<div class="container mt-5">
<div class="row justify-content-center">
<div class="col-4 text-center">
<h1 v-if="txtBuscar===''">{{titulo}}</h1>
<h1 v-else>Buscando...</h1>
<ul class="list-group">
<li class="list-group-item bg-dark">
<input type="text" v-model="txtBuscar" placeholder="Busque un contacto...">
</li>
<li class="list-group-item" v-for="(item, index) in buscarNombre">
{{index + 1}}<a href=""> {{item.name}}</a>
</li>
</ul>
</div>
<div class="class col-4 text-center">
<h1>MÁS INFO</h1>
<ul class="list-group">
<li class="list-group-item" v-for="item in listaNombres">{{item.name}}</li>
</ul>
</div>
<div class="class col-4 text-center">
<h1>JSON</h1>
<pre>
{{$data}}
</pre>
</div>
</div>
</div>
</div>
const app = new Vue({
el: '#app',
data: {
titulo: 'Agenda en VUE.js',
txtBuscar: '',
listaNombres: []
},
methods: {
//Trae los datos de la URL con AXIOS
traerDatos: function () {
var urlUsers = 'https://jsonplaceholder.typicode.com/users';
axios.get(urlUsers).then(response => {
//Almacena los datos que trae en ListaNombres.
this.listaNombres = response.data
});
}
},
//Trae los datos al iniciar...
beforeMount(){
this.traerDatos()
},
//Realiza el filtro al ingresar el nombre...
computed: {
buscarNombre: function () {
return this.listaNombres.filter((item) => item.name.includes(this.txtBuscar));
}
}
})
Here I leave the codepen: link
Thank you very much!