lokyoung / vuejs-paginate

A Vue.js(v2.x+) component for creating pagination.
MIT License
779 stars 171 forks source link

Working example with json data #99

Open oflittlemother opened 5 years ago

oflittlemother commented 5 years ago

Question: Is there a jsFiddle that has the component working with json data?

I can't figure out where to output my data so it correctly paginates. Thank you!

mkraha commented 5 years ago

+1

mkraha commented 5 years ago

Here is my code and replace JSONURL with urs. JS

Vue.component('paginate', VuejsPaginate)

new Vue({
    el: '#root',
    data () {
        return {
            products: [],
            pageCount: ''
        }
    },
    mounted() {
        this.fetchData();
    },

    methods: {
        fetchData() {
            axios.get('**JSONURL**')
            .then(response => {
                this.products = response.data.data,
                this.pageCount = response.data.last_page
            })
        },

        clickCallback: function(pageNumber) {
            axios.get("**JSONURL**?page="+ pageNumber)
            .then((response) => {
                this.products = response.data.data,
                this.pageCount = response.data.last_page
            });
        }
    }
});

HTML

<paginate
  :page-count = "pageCount"
  :page-range="5"
  :prev-text="'Prev'"
  :next-text="'Next'"
  :container-class="'pagination'"
  :page-class="'page-item'"
  :click-handler="clickCallback">
</paginate>