abusalameh's avatar

Pagination via VueJS

Hello guys, I'm having a problem with making a pagination using Laravel 5.2 & VueJS the problem is that I added a " Computed Property " that calculates the totalPages the problem is that this property gets zero value because the ajax request is too late !

0 likes
7 replies
jekinney's avatar

Have you tried

this.$nextTick(function() {
// set your pagination after ajax request is successful, if using vue-resouce in the .then function
}
1 like
goatshark's avatar

If it helps, I still use the Eloquent paginate() method that I'm using Vue to call, then I use the prev_page_url, last_page, etc. properties to build links in my view. It might not be the coolest way to accomplish the task, but it works. So my Vue methods look like this:

        fetchLogs: function() {
            this.working = true;
            this.$http.get('/api/syslog').then(function(response) {
                this.logs = response.data;
                this.working = false;
            }).catch(function(error) {
                this.errors = error;
                console.log(error);
            });
        },
        fetchPaginatedLink: function(link) {
            this.$http.get(link).then(function(response) {
                this.logs = response.data;
            }).catch(function(error) {
                this.errors = error;
                console.log(error);
            });
        }

That first call, fetchLogs, is returned from my controller using Eloquent's ->paginate() method. Then subsequent links in my view are built using the properties that ->paginate() offers, so I do things like this in my view,

@click="fetchPaginatedLink(logs.prev_page_url)"

I did this in an effort to be lazy and not figure out how to paginate with Vue.

1 like

Please or to participate in this conversation.