html:
<el-table ref="productTable" :data="productData" border
style="width: 100%" :cell-style="{ textAlign: 'center' }"
header-cell-class-name="table-th" class="productTable"
@selection-change="productMultipleChange">
<el-table-column type="selection" width="55"></el-table-column>
</el-table>
js变量:
data () {
return {
// 产品id
product_id: "",
// 产品列表数据
productData: [],
// 产品选择数据
productMultiple: []
}
},
js方法:
/**
* 产品列表回显
*/
getProductMultiple() {
this.productMultiple = [];
this.$nextTick(() => {
this.productData.forEach(item => {
if (item.id == this.product_id) {
this.productMultiple.push(item);
this.$refs.productTable.toggleRowSelection(item);
}
});
});
},
/**
* 产品列表选择改变
*/
productMultipleChange(val) {
if (val.length > 1) {
val = val.slice(val.length - 1);
this.$refs.productTable.clearSelection();
this.$refs.productTable.toggleRowSelection(val[0]);
};
this.productMultiple = [];
val.forEach(item => this.productMultiple.push(item));
}
css:
.productTable {
.table-th {
.el-checkbox {
display: none;
}
}
}