VUE使用el-pagination添加分页功能
一、添加控件
data() {
return {
suiteData: [],
suiteList: [],
pageSize:10,
currentPage: 1
};
},
mounted() {
this.getData();
},
methods:{
//获取数据
getData() {
this.$axios.get("/api/testCase").then((res)=> {
this.caseList= res.data.result;
this.getPageData()}
);
},
// 根据分页设置的数据控制每页显示的数据条数及页码跳转页面刷新
getPageData() {
let start = (this.currentPage - 1) * this.pageSize;
let end = start + this.pageSize;
this.caseData = this.caseList.slice(start, end);
},
// 分页自带的函数,当pageSize变化时会触发此函数
handleSizeChange(val) {
this.pageSize = val;
this.getPageData();
},
// 分页自带函数,当currentPage变化时会触发此函数
handleCurrentChange(val) {
this.currentPage = val;
this.getPageData();
}
}
三、实现效果
转自:https://www.jianshu.com/p/e57ab354e449