一、el-table
需加上refs
和 row-key
屬性
二、type="selection"
勾選框 需加上 reserve-selection
儲備選擇屬性
三、在分頁請求數據時,觸發 setSelected()
方法
四、在 @selection-change
變化時保存 selectedRows
< el-table ref = " tables" :data = " list" row-key = " alarmId" @selection-change = " handleSelectionChange" > < el-table-column type = " selection" width = " 55" align = " center" reserve-selection />
</ el-table>
data ( ) { return { selectedRows: [ ] }
}
getList ( ) { this . setSelected ( ) ;
} ,
setSelected ( ) { if ( this . $refs. tables) { this . $nextTick ( ( ) => { this . selectedRows. forEach ( row => { this . $refs. tables. toggleRowSelection ( row, true ) ; } ) ; } ) ; }
} ,
handleSelectionChange ( selection ) { this . ids = selection. map ( ( item ) => item. alarmId) ; this . single = selection. length != 1 ; this . multiple = ! selection. length; this . selectedRows = selection;
} ,