1,表格
<el-table
:data="tableData"
ref="multipleTable"
row-key="id" // 1,加id
stripe
style="width: 100%;"
v-loading="tableLoading"
@selection-change="handleSelectionChange" //2,该方法的参数为选中的rows
>
<el-table-column
type="selection"
reserve-selection // 3,加上该参数,保留勾选状态
width="55">
</el-table-column>
//------- 以下为自定义插槽--全选,当页------
<!-- <el-table-column width="100" fixed :reserve-selection="true">
<template #header>
<el-checkbox v-model="selectPage" @change="selectPageMethod()"
:disabled="selectAll">
{{ $t("common.selectCurrentPage") }}
</el-checkbox>
<el-checkbox
v-model="selectAll"
@change="selectAllMethod('handle')"
:disabled="selectPage"
>
{{ $t("common.selectAll") }}
</el-checkbox>
</template>
<template slot-scope="scope">
<el-checkbox
v-model="scope.row.checked"
@change="checkSingle(scope.row)"
/>
</template>
</el-table-column> -->
<el-table-column prop="companyCode" label="公司" show-overflow-tooltip>
</el-table-column>
</el-table>
//分页组件需要自定义
<pagination
v-show="paginationInfo.totalCount > 0"
:total="paginationInfo.totalCount"
:page.sync="paginationInfo.currentPage"
:limit.sync="paginationInfo.pageSize"
@pagination="paginationChange"
/>
清空复选框勾选状态调用表格上的方法:
this.$refs.multipleTable.clearSelection();
2,自定义分页组件
<template>
<div :class="{'hidden':hidden}" class="pagination-container">
<el-pagination
:background="background"
:current-page.sync="currentPage"
:page-size.sync="pageSize"
:layout="layout"
:page-sizes="pageSizes"
:total="total"
v-bind="$attrs"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
</div>
</template>
<script>
import { scrollTo } from '@/utils/scroll-to'
export default {
name: 'Pagination',
props: {
total: {
required: true,
type: Number
},
page: {
type: Number,
default: 1
},
limit: {
type: Number,
default: 20
},
pageSizes: {
type: Array,
default() {
return [10, 20, 30, 50]
}
},
layout: {
type: String,
default: 'total, sizes, prev, pager, next, jumper'
},
background: {
type: Boolean,
default: true
},
autoScroll: {
type: Boolean,
default: true
},
hidden: {
type: Boolean,
default: false
}
},
computed: {
currentPage: {
get() {
return this.page
},
set(val) {
this.$emit('update:page', val)
}
},
pageSize: {
get() {
return this.limit
},
set(val) {
this.$emit('update:limit', val)
}
}
},
methods: {
handleSizeChange(val) {
this.$emit('pagination', { page: this.currentPage, limit: val })
if (this.autoScroll) {
scrollTo(0, 800)
}
},
handleCurrentChange(val) {
this.$emit('pagination', { page: val, limit: this.pageSize })
if (this.autoScroll) {
scrollTo(0, 800)
}
}
}
}
</script>
<style scoped>
.pagination-container {
background: #fff;
padding: 10px 16px;
}
.pagination-container.hidden {
display: none;
}
</style>