需求1:table組件的checkbox進行數據重顯,默認顯示已選中數據
// html <Table ref="multipleTable" :data="dataArr" > <el-table-column type="selection" align="center"></el-table-column> </Table> // js // table數據 let dataArr = [{name:'張三',id:1},{name:'李四',id:2}]; // 已選數據ID數組 let IDArr = [2]; // 復選 reselectFun(dataArr, IDArr ){ this.$nextTick(function() { dataArr.forEach(row => { if (IDArr.includes(row.id)) { this.$refs.multipleTable.toggleRowSelection(row, true); } }); }); }
需求2:獲取所有的選中數據
// 保存按鈕 save(){ // this.$refs.multipleTable.selection 獲取所有選中的數據 console.log(this.$refs.multipleTable.selection) }