html部分
<div class="page">
<button class="btn btn-default" type="submit" @click="primaryPage">首页</button>
<button class="btn btn-default" type="submit" @click="prePage">上页</button>
<button class="btn btn-default" type="submit">{{current_page}}/{{Math.ceil(arrs.length/pagesize)}}</button>
<button class="btn btn-default" type="submit" @click="nextPage">下页</button>
<button class="btn btn-default" type="submit" @click="lastPage">尾页</button>
</div>
vue部分
data : {
currentPage : 1,//当前页号
pagesize :10 //每页大小
}
computed:{
page_arrs(){
let {currentPage,pagesize} = this
return this.arrs.slice((currentPage-1)*pagesize,currentPage*pagesize)
},
current_page(){
return this.currentPage
}
},
methods: {
primaryPage(){
this.currentPage = 1
},
prePage(){
if(this.currentPage == 1){
return
}
this.currentPage = this.currentPage - 1
},
nextPage(){
if(this.currentPage == Math.ceil(this.arrs.length/this.pagesize)){
return
}
this.currentPage = this.currentPage + 1
},
lastPage(){
this.currentPage = Math.ceil(this.arrs.length/this.pagesize)
}
},
本文详细介绍了如何使用Vue.js创建一个动态分页组件,包括HTML结构设计、Vue数据绑定及事件处理,实现首页、上一页、下一页和尾页等功能。通过计算属性展示当前页数和总页数,确保用户可以轻松浏览大量数据。
4387

被折叠的 条评论
为什么被折叠?



