Html:
<div class="pageNum">
<button @click="firstPage">首页</button>
<button @click="backPage">上一页</button>
<ul>
<li :class="{active:page===currentPage}" v-for="page in totalPage" @click="toPage(page)">{{page}}
/li>
</ul>
<button @click="forwardPage">下一页</button>
<button @click="lastPage">尾页</button>
</div>
vue代码:
<script>
new Vue({
el: "#pageNum",
data: {
//分页参数
currentPage: 1, //当前页
pageSize: 6, //页容量
totalPage: '',//总页数
totalCount: '',//总记录数
courseList: '',//接收后台发送的数据容器
},
methods: {
//分页_搜索
findAll() {
var url = "http://localhost:8080/edu/courses";
axios.get(url, {
params: {
method: "findAll",
//分页
currentPage: this.currentPage,
pageSize: this.pageSize,
}
})
.then(res => {
console.log(res);
this.currentPage = res.data.obj.currentPage
this.pageSize = res.data.obj.pageSize
this.totalCount = res.data.obj.totalCount
this.totalPage = res.data.obj.totalPage
this.courseList = res.data.obj.data
})
},
/* 首页 */
firstPage() {
this.currentPage = 1;
this.findAll();
},
/* 尾页 */
lastPage() {
this.currentPage = this.totalPage;
this.findAll();
},
/* 上一页 */
backPage() {
if (this.currentPage == 1) {
return;
}
this.currentPage = this.currentPage - 1;
this.findAll();
},
/* 下一页 */
forwardPage() {
if (this.currentPage == this.totalPage) {
return;
}
this.currentPage = this.currentPage + 1;
this.findAll();
},
/* 跳转到xx页 */
toPage(page){
this.currentPage=page;
this.findAll();
},
},
created() {
this.findAll();
},
})
</script>