VUE-element UI 配置点击行展开

665 阅读1分钟

expands: [],

el-table 设置

:row-key="getRowKeys"

:row-class-name="tableRowClassName"

@row-click="clickRowHandle"

:expand-row-keys="expands"

@expand-change="expandSelect"

第一列设置:type="expand"

getRowKeys: function (row) {      // alert(row.id)      return row.id;      // return row.manufacturer    },



expandSelect: function (row, expandedRows) {     
 var that = this;     
 if (expandedRows.length) {        
that.expands = [];        
if (row) {          
that.expands.push(row.id);        
}     
 } 
else {        
that.expands = [];      
}    
},

在row-click 函数中配置

 if (this.expands.includes(row.id)) {

this.expands = this.expands.filter((val) => val !== row.id);

} else {

this.expands.push(row.id);

}