module.exports = {
props: {
data: {
type: Object,
default: function() {
return {
current_page: 1,
data: [],
from: 1,
last_page: 1,
next_page_url: null,
per_page: 10,
prev_page_url: null,
to: 1,
total: 0,
}
}
},
limit: {
type: Number,
default: 0
}
},
template: '
',
methods: {
selectPage: function(page) {
this.$emit('pagination-change-page', page);
},
getPages: function() {
if (this.limit === -1) {
return 0;
}
if (this.limit === 0) {
return this.data.last_page;
}
var start = this.data.current_page - this.limit,
end = this.data.current_page + this.limit + 1,
pages = [],
index;
start = start < 1 ? 1 : start;
end = end >= this.data.last_page ? this.data.last_page + 1 : end;
for (index = start; index < end; index++) {
pages.push(index);
}
return pages;
}
}
};