|
| 1 | +module.exports = { |
| 2 | + template: '<nav class=" {{navClass}} ">' + |
| 3 | + '<ul class="pagination {{size}} ">' + |
| 4 | + '<li v-if="pagination.current_page > 1">' + |
| 5 | + '<a href="#" aria-label="Previous" @click.prevent="changePage(1)">' + |
| 6 | + '<span aria-hidden="true">First</span>' + |
| 7 | + '</a>' + |
| 8 | + '</li>' + |
| 9 | + '<li v-if="pagination.current_page > 1">' + |
| 10 | + '<a href="#" aria-label="Previous" @click.prevent="changePage(pagination.current_page - 1)">' + |
| 11 | + '<span aria-hidden="true">«</span>' + |
| 12 | + '</a>' + |
| 13 | + '</li>' + |
| 14 | + '<li v-if="pagination.current_page > 1">' + |
| 15 | + '<a href="#" aria-label="Next" @click.prevent="changePage(from)">' + |
| 16 | + '<span aria-hidden="true">...</span>' + |
| 17 | + '</a>' + |
| 18 | + '</li>' + |
| 19 | + '<li v-for="num in data" :class="{\'active\': num == pagination.current_page}">' + |
| 20 | + '<a href="#" @click.prevent="changePage(num)">{{ num }}</a>' + |
| 21 | + '</li>' + |
| 22 | + '<li v-if="pagination.current_page < pagination.total_pages">' + |
| 23 | + '<a href="#" aria-label="Next" @click.prevent="changePage(to)">' + |
| 24 | + '<span aria-hidden="true">...</span>' + |
| 25 | + '</a>' + |
| 26 | + '</li>' + |
| 27 | + '<li v-if="pagination.current_page < pagination.total_pages">' + |
| 28 | + '<a href="#" aria-label="Next" @click.prevent="changePage(pagination.current_page + 1)">' + |
| 29 | + '<span aria-hidden="true">»</span>' + |
| 30 | + '</a>' + |
| 31 | + '</li>' + |
| 32 | + '<li v-if="pagination.current_page < pagination.total_pages">' + |
| 33 | + '<a href="#" aria-label="Next" @click.prevent="changePage(pagination.total_pages)">' + |
| 34 | + '<span aria-hidden="true">Last</span>' + |
| 35 | + '</a>' + |
| 36 | + '</li>' + |
| 37 | + '</ul>' + |
| 38 | + '</nav>', |
| 39 | + |
| 40 | + data: function(){ |
| 41 | + return { |
| 42 | + to : 0, |
| 43 | + from: 0 |
| 44 | + } |
| 45 | + }, |
| 46 | + props: { |
| 47 | + pagination: { |
| 48 | + type: Object, |
| 49 | + required: true |
| 50 | + }, |
| 51 | + callback: { |
| 52 | + type: Function, |
| 53 | + required: true |
| 54 | + }, |
| 55 | + size: { |
| 56 | + type: String, |
| 57 | + default: "" |
| 58 | + }, |
| 59 | + navClass: { |
| 60 | + type: String, |
| 61 | + default: "" |
| 62 | + }, |
| 63 | + offset: { |
| 64 | + type: Number, |
| 65 | + default: 4 |
| 66 | + } |
| 67 | + }, |
| 68 | + computed: { |
| 69 | + data: function () { |
| 70 | + var from = this.pagination.current_page - this.offset; |
| 71 | + if(from < 1) { |
| 72 | + from = 1; |
| 73 | + } |
| 74 | + |
| 75 | + var to = from + (this.offset * 2); |
| 76 | + if(to >= this.pagination.total_pages) { |
| 77 | + to = this.pagination.total_pages; |
| 78 | + } |
| 79 | + this.from = from; |
| 80 | + this.to = to; |
| 81 | + |
| 82 | + var arr = []; |
| 83 | + while (from <=to) { |
| 84 | + arr.push(from); |
| 85 | + from++; |
| 86 | + } |
| 87 | + |
| 88 | + return arr; |
| 89 | + } |
| 90 | + }, |
| 91 | + watch: { |
| 92 | + 'pagination.per_page': function () { |
| 93 | + this.callback(); |
| 94 | + } |
| 95 | + }, |
| 96 | + methods: { |
| 97 | + changePage: function (page) { |
| 98 | + this.$set('pagination.current_page', page); |
| 99 | + this.callback(); |
| 100 | + } |
| 101 | + } |
| 102 | +}; |
0 commit comments