el-table实现跨页多选
时间: 2023-11-11 07:00:46 浏览: 209
可以通过以下步骤实现el-table的跨页多选:
1. 在el-table中添加selection属性,用于存储选中的行数据。
2. 在el-table-column中添加type属性,设置为selection,用于显示复选框。
3. 在el-pagination中添加@current-change事件,用于监听分页器的页码变化。
4. 在@current-change事件中,判断当前页是否为第一页,如果是,则将选中的行数据存储到selection中;如果不是,则将选中的行数据追加到selection中。
5. 在el-table中添加@select-all事件,用于全选当前页的数据。
6. 在@select-all事件中,判断当前页是否为第一页,如果是,则将当前页的所有数据存储到selection中;如果不是,则将当前页的所有数据追加到selection中。
以下是示例代码:
```
<template>
<div>
<el-table :data="tableData" :row-key="row => row.id" @select-all="handleSelectAll">
<el-table-column type="selection"></el-table-column>
<el-table-column prop="name" label="姓名"></el-table-column>
<el-table-column prop="age" label="年龄"></el-table-column>
</el-table>
<el-pagination :total="total" :page-size="pageSize" @current-change="handlePageChange"></el-pagination>
</div>
</template>
<script>
export default {
data() {
return {
tableData: [],
selection: [],
total: 0,
pageSize: 10,
currentPage: 1
}
},
methods: {
handlePageChange(currentPage) {
if (currentPage === 1) {
this.selection = []
}
this.currentPage = currentPage
},
handleSelectAll(selection) {
if (this.currentPage === 1) {
this.selection = selection
} else {
this.selection = this.selection.concat(selection)
}
}
}
}
</script>
```
阅读全文
相关推荐

















