Vue.component('latest-posts', {
props: ['posts'],
template: `
`
});
Vue.component('latest-posts-index', {
props: ['posts'],
template: `
`
});
Vue.component('post-details', {
props: ['details'],
template: `
{{ details.titulo }}
{{ details.fecha }}
`
});
Vue.component('posts', {
props: ['publish'],
template: `
{{ publish.fecha }}
{{ publish.titulo }}
{{ publish.preview }}
Leer más
`
});
var blog = new Vue({
el: '#publicaciones',
data: {
publicaciones: [],
post: [],
verDetalles: false,
search: '',
perPage: 3,
currentPage: 1,
totalRows: 2,
verPaginador: true
},
created() {
this.getData();
},
computed: {
filtroBusqueda: function() {
if (this.search.length != 0) {
this.verPaginador = false;
return arrFilter = this.publicaciones.filter((pub) => {
return pub.titulo.toLowerCase().match(this.search.toLowerCase())
});
} else {
// Implementar páginador
this.verPaginador = true;
return this.paginador();
}
},
filtrolatestPub: function() {
// Calculamos los 3 últimos
var publiTotal = parseInt(this.publicaciones.length) - 3;
return arrFilter = this.publicaciones.filter((pub) => {
return pub.id > publiTotal
});
},
rows() {
return this.publicaciones.length
}
},
methods: {
verNoticia: function(id) {
this.verDetalles = true;
this.post = this.publicaciones.filter(function(pub) {
return pub.id == id
});
},
paginador() {
// Calcular páginador
const indiceInicio = (this.currentPage - 1) * this.perPage;
const indiceFinal = indiceInicio + this.perPage > this.publicaciones.length ?
this.publicaciones.length :
indiceInicio + this.perPage;
return this.publicaciones.slice(indiceInicio, indiceFinal);
},
getData() {
axios.get("./shared/data/publicaciones.json")
.then(response => { this.publicaciones = response.data });
}
}
});