| | |
| | | type="index" |
| | | width="60" |
| | | align="center" |
| | | /> <template v-for="col in columns" :key="col.prop"> |
| | | <el-table-column |
| | | v-bind="col" |
| | | align="center" |
| | | > |
| | | /> |
| | | <template v-for="col in columns" :key="col.prop"> |
| | | <el-table-column v-bind="col" align="center"> |
| | | <template #default="scope"> |
| | | <template v-if="col.slot"> |
| | | <slot |
| | |
| | | :column="scope.column" |
| | | :index="scope.$index" |
| | | ></slot> |
| | | </template> <template v-else> |
| | | </template> |
| | | <template v-else> |
| | | <div |
| | | class="cell-edit" |
| | | @dblclick="handleCellEdit(scope.row, col.prop)" |
| | |
| | | class="cell-text" |
| | | > |
| | | {{ |
| | | formatCellValue(scope.row, scope.column, scope.row[col.prop], col) |
| | | formatCellValue( |
| | | scope.row, |
| | | scope.column, |
| | | scope.row[col.prop], |
| | | col |
| | | ) |
| | | }} |
| | | </span> |
| | | <!-- 编辑状态:使用原始值,不经过格式化 --> |
| | |
| | | // 格式化单元格值 |
| | | const formatCellValue = (row, column, cellValue, col) => { |
| | | // 如果列有自定义格式化器,使用自定义格式化器 |
| | | if (col.formatter && typeof col.formatter === 'function') { |
| | | if (col.formatter && typeof col.formatter === "function") { |
| | | return col.formatter(row, column, cellValue); |
| | | } |
| | | // 否则使用默认格式化器 |