分页功能
1、前后端共同实现
<template>
<div>
<el-pagination
background
@current-change="handleCurrentChange"
:page-size="pageSize"
:current-page="currentPage"
layout="total,prev, pager, next"
:total="total">
</el-pagination>
</div>
</template>
<script>
export default {
data() {
return {
tableData: [],
total: 0,
pageIndex: 1,
pageSize: 20,
currentPage: '',
}
},
methods: {
select() {
let params = {
strKey: this.strkey,
page: this.currentPage,
pageSize: this.pageSize
}
axios({
method: '请求类型',
url: '请求地址',
data: params
}).then(res => {
this.total = res.data.count
})
},
handleCurrentChange(val) {
this.currentPage = val;
this.select();
}
}
}
</script>
2、前端自己实现:
<template>
<div>
<el-pagination
background
@current-change="handleCurrentChange"
:page-size="pageSize"
:current-page="currentPage"
layout="total,prev, pager, next"
:total="total">
</el-pagination>
</div>
</template>
<script>
import { getcustomqueryresults } from '@/utils/https'
export default {
data() {
return {
tableData: [],
currentPage: 1,
PageSize: 20,
total: 0,
}
},
methods: {
select() {
().then(res => {
this.tableData = res.data.slice(
(this.currentPage - 1) * this.PageSize,
this.currentPage * this.PageSize
)
this.total = Number(res.count)
})
},
handleCurrentChange(val) {
console.log(val, 'val当前页')
this.currentPage = val
this.select()
},
}
}
</script>