0👍
✅
You need to implement pagination. Pagination is server side, so you need to edit your controller. If you use Laravel, take a look at pagination. Else, you have to write your own paganiation, somithing like (just as an Idea)
$page = $_GET['page'];
$perPage = 10;
$offset = $page*$perpage;
SELECT * FROM abc LIMIT $perpage OFFSET $offset
If you have your pagination working, you then simply would need to send the page you want together with your request:
axios.get('/api/comments', {
params: {
page: this.currentPage + 1
}
}).then(res => {
this.reviews = res.data;
this.currentpage++;
});
this would return the results paginated.
EDIT
To use pagination in Laravel: You just have to change the ending of your Eloquent query, your Query should look someting like this:
$return = Comment::where('a', 1)->paginate(itemsPerPage); //use ->paginate()
return response()->json($return);
You are getting all information you need to work with, the axios request I’ve written before would work. You just have to define the page you want to get back. Just read the link to pagination, it’s really good.
Source:stackexchange.com