element table跨分頁多選及回顯的實現(xiàn)示例
更新時間:2022年02月23日 10:11:36 作者:妮可是條狗
本文主要介紹了element table跨分頁多選及回顯的實現(xiàn)示例,文中通過示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
1.data中定義getRowKeys,記錄每行的key值
getRowKeys(row) {
? ?return row.id;
},2.el-table綁定getRowKeys
<el-table ? ? :data="tableData" ? ? @selection-change="handleSelectionChange" ? ? :row-key="getRowKeys" >
3.將selection列的reserve-selection設(shè)為true
<el-table-column ? ? type="selection" ? ? width="50" ? ? align="center" ? ? :reserve-selection="true" ></el-table-column>
4.表格數(shù)據(jù)選中方法handleSelectionChange
handleSelectionChange(rows) {
? ? this.multipleSelection = rows;
? ? this.select_number = this.multipleSelection.length;
? ? this.select_Id = [];
? ? if (rows) {
? ? ? ? rows.forEach((row) => {
? ? ? ? ? if (row) {
? ? ? ? ? ? this.select_Id.push(row.id);
? ? ? ? ? }
? ? ? ? });
? ? }
},代碼整理
<template>
? <div>
? ? <el-table @selection-change="handleSelectionChange" :row-key="getRowKeys">
? ? ? <el-table-column type="selection" width="50" align="center" :reserve-selection="true">?
? ? ? </el-table-column>
? ? </el-table>
? ? <el-pagination>...</el-pagination>
? </div>
</template>
<script>
export default {
? data() {
? ? return {
? ? ? multipleSelection: [], // 表格選中
? ? ? getRowKeys(row) {//記錄每行的key值
? ? ? ? return row.id;
? ? ? },
? ? ? select_number: "", //表格select選中的條數(shù)
? ? ? select_Id: [], //表格select復選框選中的id
? ? }
? },
? methods: {
? ? handleSelectionChange(rows) {
? ? ? this.multipleSelection = rows;
? ? ? this.select_number = this.multipleSelection.length;
? ? ? this.select_Id = [];
? ? ? if (rows) {
? ? ? ? rows.forEach((row) => {
? ? ? ? ? if (row) {
? ? ? ? ? ? this.select_Id.push(row.id);
? ? ? ? ? }
? ? ? ? });
? ? ? }
? ? },
? }
}到此這篇關(guān)于element table跨分頁多選及回顯的實現(xiàn)示例的文章就介紹到這了,更多相關(guān)element table跨分頁多選及回顯內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Vue + iView實現(xiàn)Excel上傳功能的完整代碼
前一段時間項目經(jīng)歷了前端上傳文件的過程,首先進入頁面會展示默認的樣子,選中要上傳的excel文件,本文通過實例圖文相結(jié)合給大家介紹的非常詳細,需要的朋友參考下吧2021-06-06

