:cell-class-name="addCellClass"
:header-cell-class-name="addCellClass"
可以通过指定 组件的 row-class-name
属性来为 crud 中的某一行添加 class,表明该行处于某种状态,返回当前行的row
数据和行的序号index;
header-cell-class-name 表头单元格的className的回调方法,也可以使用字符串为所有表头单元格设置一个固定的className
<template>
<div class="tableCrudBox">
<avue-crud
ref="tableCrudDialog"
class="tableCrud"
:data="tableData"
:option="tableOptions"
:table-loading="showLoading"
:cell-class-name="addCellClass"
:header-cell-class-name="addCellClass"
>
</avue-crud>
</div>
</template>
methods: {
addCellClass({ row, column }) {
// 'aaa','bbb'为列的 prop
const leftArr = ['aaa','bbb'], rightArr = ['ccc','ddd'], centerArr = ['eee','fff']
if (leftArr.includes(column.property)) {
return 'cell-left'
} else if (rightArr.includes(column.property)) {
return 'cell-right'
} else if (centerArr.includes(column.property)) {
return 'cell-center'
}
}
}
通过addCellClass()方法为表格的头和行添加了指定的class,接下来为指定类设置样式:
<style lang="scss" scoped>
.tableCrudBox{
.tableCrud{
// 表头样式
/deep/ .el-table th.el-table__cell.is-leaf.cell-left {
text-align: left;
}
/deep/ .el-table th.el-table__cell.is-leaf.cell-right {
text-align: right;
}
/deep/ .el-table th.el-table__cell.is-leaf.cell-center {
text-align: center;
}
// 表格行样式
/deep/ .el-table td.el-table__cell.cell-left {
text-align: left;
}
/deep/ .el-table td.el-table__cell.cell-right {
text-align: right;
}
/deep/ .el-table td.el-table__cell.cell-center {
text-align: center;
}
}
}
</style>