import api from '@/api/api' import { httpGet, httpPost } from '@/api/fetch-api.js' export default { name: "pagination", props: { total: { type: Number, default: 1 } }, data() { return { // total: 10, // 总页数 cur: 1, // 当前页码 sel: 1, // 选择的页码 } }, components: {}, computed: { offSet: function () { return (this.cur - 1) * 5 }, indexs: function () { var left = 1 var right = this.total var ar = [] if (this.total >= 11) { if (this.cur > 5 && this.cur < this.total - 4) { left = this.cur - 5 right = this.cur + 4 } else { if (this.cur <= 5) { left = 1 right = 10 } else { right = this.total left = this.total - 9 } } } while (left <= right) { ar.push(left) left++ } return ar } }, methods: { jumpPage() { this.cur = this.sel; if (this.cur < 1) this.cur = 1; if (this.cur > this.total) this.cur = this.total; this.sendPage(); }, selPage(data) { //页码点击事件 if (data == this.cur) return; this.cur = data; this.sel = this.cur; this.sendPage(); }, prevPage() { this.cur--; if (this.cur < 1) this.cur = 1; this.sel = this.cur; this.sendPage(); }, nextPage() { this.cur++; if (this.cur > this.total) this.cur = this.total; this.sel = this.cur; this.sendPage(); }, sendPage() { // 发送事件 this.$emit("selpage", { page: this.cur }); }, initData() {} }, mounted() {}, created() {} }