-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathvue-nav.js
69 lines (66 loc) · 1.56 KB
/
vue-nav.js
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
(function(){
var tm = '<div class="page-bar">'+
'<ul>'+
'<li v-if="cur!=1"><a @click="btnClick(cur-1)">上一页</a></li>'+
'<li v-for="index in indexs" v-bind:class="{ active: cur == index}">'+
'<a v-on:click="btnClick(index)">{{ index }}</a>'+
'</li>'+
'<li v-if="cur!=all"><a @click="btnClick(cur+1)">下一页</a></li>'+
'<li><a>共<i>{{all}}</i>页</a></li>'+
'</ul>'+
'</div>'
var navBar = Vue.extend({
template: tm,
props: {
cur: {
type: [String, Number],
required: true
},
all: {
type: [String, Number],
required: true
},
callback: {
default() {
return function callback() {
// todo
}
}
}
},
computed: {
indexs() {
var left = 1
var right = this.all
var ar = []
if (this.all >= 11) {
if (this.cur > 5 && this.cur < this.all - 4) {
left = this.cur - 5
right = this.cur + 4
} else {
if (this.cur <= 5) {
left = 1
right = 10
} else {
right = this.all
left = this.all -9
}
}
}
while (left <= right) {
ar.push(left)
left ++
}
return ar
}
},
methods: {
btnClick(page) {
if (page != this.cur) {
this.callback(page)
}
}
}
})
window.Vnav = navBar
})()