pagination.js
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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() {}
}