具体效果
javascript
<el-table-column
align="center"
width="100px"
:render-header="(h) =>renderHeader(h,'列名')"
>
<template slot-scope="scope">
<el-switch
v-model="scope.row['列名']"
@change="(value) =>updatePlanStatus(scope.row,'列名',scope.$index,value)"
/>
</template>
</el-table-column>
javascript
renderHeader(h, name) {
return h("div", [
h("el-checkbox", {
style: "margin-right:5px",
// 普通的 HTML 属性
attrs: {
id: "check1"
},
on: {
change: value => {
if (this.selectPoints.length > 0) {
this.$nextTick(() => {
// selectPoints 是选中的列
this.selectPoints.forEach((item, key) => {
item[name] = value;
// 判断数组下标
const index = this.pointsList.findIndex(
point => item.cabinNo == point.cabinNo
);
// 更新表格数据
this.$set(this.pointsList, index, { ...item });
// 上一句执行后所有选中的列都会被清除,需要重新选中
this.$refs.pointTable.toggleRowSelection(
this.pointsList[index],
true
);
});
});
}
}
}
}),
h("span", name)
]);
},
javascript
在这里插入代码片