By now, we have our pagination
object but we always fetch the first page of stories since we are making a GET
HTTP request to api/stories
. We have to change the requested page based on user input (next page, previous page).
First we'll update the fetchStories
method to accept an argument with the desired page. If no argument is passed, it will fetch the first page. I'll also create a new method makePagination
to make the code cleaner:
new Vue({ ... methods: { ... fetchStories: function (page_url) { var vm = this; page_url = page_url || '/api/stories' this.$http.get(page_url) .then(function (response) { var storiesReady = response.data.data.map (function (story) { story.editing = false; return story }) vm...