Skip to content

Commit cdf36a6

Browse files
author
wuqiong
committed
page
0 parents  commit cdf36a6

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

page.html

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<meta http-equiv="X-UA-Compatible" content="ie=edge">
8+
<title>分页</title>
9+
<style>
10+
body {
11+
font-family: "Segoe UI";
12+
}
13+
14+
li {
15+
list-style: none;
16+
}
17+
18+
a {
19+
text-decoration: none;
20+
}
21+
22+
.pagination {
23+
position: relative;
24+
}
25+
26+
.pagination li {
27+
display: inline-block;
28+
margin: 0 5px;
29+
}
30+
31+
.pagination li a {
32+
padding: .5rem 1rem;
33+
display: inline-block;
34+
border: 1px solid #ddd;
35+
background: #fff;
36+
37+
color: #0E90D2;
38+
}
39+
40+
.pagination li a:hover {
41+
background: #eee;
42+
}
43+
44+
.pagination li.active a {
45+
background: #0E90D2;
46+
color: #fff;
47+
}
48+
</style>
49+
</head>
50+
51+
<body>
52+
<script type="text/x-template" id="page">
53+
<ul class="pagination">
54+
<li v-show="current != 1" @click="current-- && goto(current)">
55+
<a href="#">上一页</a>
56+
</li>
57+
<li v-for="index in pages" @click="goto(index)" :class="{'active':current == index}" :key="index">
58+
<a href="#">{{index}}</a>
59+
</li>
60+
<li v-show="allpage != current && allpage != 0 " @click="current++ && goto(current++)">
61+
<a href="#">下一页</a>
62+
</li>
63+
</ul>
64+
</script>
65+
<div id="app">
66+
<page></page>
67+
</div>
68+
<script src="https://cdn.bootcss.com/vue/2.5.13/vue.min.js"></script>
69+
<script>
70+
Vue.component("page", {
71+
template: "#page",
72+
data: function () {
73+
return {
74+
current: 1, // 当前页码
75+
showItem: 5, // 最少显示5个页码
76+
allpage: 13 // 总共的
77+
}
78+
},
79+
computed: {
80+
pages: function () {
81+
var pag = [];
82+
if (this.current < this.showItem) { //如果当前的激活的项 小于要显示的条数
83+
//总页数和要显示的条数那个大就显示多少条
84+
var i = Math.min(this.showItem, this.allpage);
85+
while (i) {
86+
pag.unshift(i--);
87+
}
88+
} else { //当前页数大于显示页数了
89+
var middle = this.current - Math.floor(this.showItem / 2), //从哪里开始
90+
i = this.showItem;
91+
if (middle > (this.allpage - this.showItem)) {
92+
middle = (this.allpage - this.showItem) + 1
93+
}
94+
while (i--) {
95+
pag.push(middle++);
96+
}
97+
}
98+
return pag
99+
}
100+
},
101+
methods: {
102+
goto: function (index) {
103+
if (index == this.current) return;
104+
this.current = index;
105+
//这里可以发送ajax请求
106+
}
107+
}
108+
})
109+
110+
var vm = new Vue({
111+
el: '#app',
112+
})
113+
</script>
114+
</body>
115+
116+
</html>

0 commit comments

Comments
 (0)