1、在 el-table中,設置table的唯一標識:row-key="id",在復選框列中,設置 reserve-selection ,設置為 true 時,則點擊分頁的時候,根據table中的 row-key ,來保留之前選中的數據,
<!-- 表格控件 -->
<el-table :data="tableData" style="width: 100%" :fit="true" @selection-change="handleSelectionChange" row-key="id" :header-cell-style="{background:'#F0F2F5',color:'#585858',textAlign: 'center',fontSize: '12px'}" > <el-table-column type="selection" align="center" reserve-selection width="55"> </el-table-column> <el-table-column prop="merId" min-width="90" align="center" show-overflow-tooltip label="商戶號"> <template slot-scope="scope"> {{scope.row.refId}}({{scope.row.refname}}) </template> </el-table-column> </el-table>
<!-- 分頁控件 --> <div class="pagein_box"> <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pageNo" :page-sizes="[10, 20, 30 ,40]" layout=" prev, pager, next,sizes, jumper, total" :total="pageInfo.totalNum" :pager-count= "5" > </el-pagination> </div>
2、
// 獲取當前點擊的每頁幾條 handleSizeChange(val) { this.pageSize = val; this.getRoleLists(); }, // 點擊切換分頁頁碼,獲取當前點擊的是第幾頁 handleCurrentChange(val) { this.pageNo = val; this.getRoleLists(); },
3、獲取選中的id:
function handleSelectionChange(val: any) { this.multipleSelection = val; console.log(this.multipleSelection); };