1. template分页
<el-pagination
:page-size="fileListForm.pageSize"
:current-page="fileListForm.pageNum"
:page-sizes="[10, 50, 100, 200, 300, 500, 1000]"
layout="total, sizes, prev, pager, next, jumper"
:total="fileListForm.total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
2.data定义
fileListForm: {
fileOldName: '', // 按照name查询
pageSize: 10, // 每页多少条
pageNum: 1, // 默认第一页
total: 0, // 总条数
},
3. 点击下一页和改变每页的条数
// 点击下一页
handleCurrentChange(currentPage) {
this.fileListForm.pageNum = currentPage;
this.getUploadFile();
},
// 每页显示的条数
handleSizeChange(val) {
this.fileListForm.pageSize = val;
this.fileListForm.pageNum = 1;
this.getUploadFile();
},
4.默认列表查询
// 默认列表
async getUploadFile() {
const uploadObj = await uploadHomeDownloadFile(this.fileListForm);
if (uploadObj.code === 0) {
this.fileListForm.total = uploadObj.data.count;
this.uploadFileList = uploadObj.data.list;
this.indicatorLoading = false;
}
},
5.根据name来搜索(点击搜索按钮)
此时页数应变为默认第一页 且 总条数为0
// 搜索
async searchUploadFile() {
this.fileListForm.pageNum = 1;
this.fileListForm.total = 0;
this.indicatorLoading = true;
const uploadObj = await uploadHomeDownloadFile(this.fileListForm);
if (uploadObj.code === 0) {
this.fileListForm.total = uploadObj.data.count;
this.uploadFileList = uploadObj.data.list;
this.indicatorLoading = false;
}
},
6.重置(刷新)查询条件清空且重新加载列表
// 刷新--重置
resetUploadFile() {
this.indicatorLoading = true;
this.fileListForm = {
fileOldName: '',
pageSize: this.fileListForm.pageSize,
pageNum: 1,
total: 0,
};
this.getUploadFile();
},
7.删除文件或table某一行
表格某一行传值scope.row 即deleteFile(scope.row.id)
// 删除文件
deleteFile(id) {
this.$confirm('是否删除该文件?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(async () => {
const resultObj = await deleteUploadDownload(id);
if (resultObj.code === 0) {
this.$message({
type: 'success',
message: '删除成功!',
});
this.getUploadFile();
}
});
},