Feb 16, 2017
0
Level 1
Access Vue Property on ready/computed
I have a Pagination component. For this component, I need to access the 'paginateditems' property on page load to obtain the total pages for the paginator. I try to do this on both ready and created, but each time I get an error that the property is 'undefined'
props: ['paginateditems'],
ready: function() {
console.log(this.paginateditems.total_pages) //returns 'undefined' even though the value is 100... logging (this.paginateditems) returns an object but without data
},
computed: {
currentVisiblePages: function(){
let totalPages = this.paginateditems.total_pages // this value IS available in the computed property
let pageRange = this.pageRange
var pages = []
for(var i = 0; i < 5; i++){
if(pageRange[i] <= totalPages){
pages.push(pageRange[i])
}
}
return pages
}
},
// Pagination component being called from parent
<pagination :paginateditems="pagination" :resultsperpage="resultsPerPage" @numpageschanged="numPagesChange" @pagechanged="fetchAllRecords">
</pagination>
Please or to participate in this conversation.