Vue.js is a lightweight, high-performance, and modular MVVM library with a very easy to access API.
Page General and table together, pagination link as part of the table, the paging link encapsulated into a separate component, and then as a child component embedded in the table component, this is more reasonable.
1. Register a component
Js
Vue.component (' pagination ', {
template: ' #paginationTpl ',
replace:true,
props:[' cur ', ' all ', ' pagenum ' ],
methods:{
//page number Click event
btnclick:function (index) {
if (index!= this.cur) {
this.cur = index
}
}
,
watch:{
"cur": function (val,oldval) {this
. $dispatch (' Page-to ', val)
}
} ,
computed:{
indexes:function () {
var list = []
//Calculate left and right page
var mid = parseint (THIS.PAGENUM/2) ;//median value
var left = This.cur-mid;
var right = Math.max (this.cur + this.pagenum-mid-1,this.pagenum);
if (left < 1) {left = 1}
if (right > This.all) {right = This.all} while
(left <= right) {
List.pu SH (left) left
+ +
} return
list;
showlast:function () {
if (this.cur = = This.all) { Return
false
}
return True
},
showfirst:function () {
if (this.cur = = 1) {return
false
} return
True
}
}
});
Template:
<script type= "Text/template" id= "Paginationtpl" >
<nav v-if= "all > 1" >
<ul class= " Pagination ">
<li v-if=" Showfirst "><a href=" javascript: "@click =" cur--">«</a></li>
<li v-for= "index in Indexes": class= "{' active ': cur = = index}" >
<a @click = "Btnclick (index)" href= " javascript: ">{{index}}</a>
</li>
<li v-if=" Showlast "><a @click =" cur++ "href=" javascript: ">»</a></li>
<li><a> Total <i>{{all}}</i> page </a></li >
</ul>
</nav>
</script>
Html:
<div id= ' Parentele ' > ...
<pagination:cur= "1": all= "Pageall":p age-num= "ten" @page-to= "loadlist" ></pagination>
</div>
When you click the paging link, it triggers
Page-to
event, and we specified the use of the parent component in the HTML tag
Loadlist
Method handles events, we simply pass the current page number to the parent component in the component, which is responsible for Ajax loading of the data and updating its own Pageall value.