赞
踩
首先官网文档的 Table 表格 组件有相关说明,只需要在el-table标签中加上:cell-style="xxx",以及实现该方法即可。Element UI框架和Element Plus框架在使用上有一点点区别,因此记录一下下。
(1)/src/views/Example/CellStyle/index_1.vue
- <el-table
- border
- size="mini"
- row-key="id"
- highlight-current-row
- :data="feats.list"
- :cell-style="handleChangeCellStyle"
- >
- <el-table-column label="评分" width="100" align="center">
- <template slot-scope="scope">
- <el-link type="danger">{{ scope.row.score }}</el-link>
- </template>
- </el-table-column>
- </el-table>
-
- methods: {
- /**
- * 改变表格单元格颜色
- */
- handleChangeCellStyle({row, column, rowIndex, columnIndex}) {
- let cellStyle
- if (row.score > 9) {
- cellStyle = 'background-color: #ffdcdc'
- }
- else if (row.score > 7) {
- cellStyle = 'background-color: #fde2c2'
- }
- else {
- cellStyle = 'background-color: #fff'
- }
-
- if (column.label === '评分') {
- return cellStyle
- }
- },
- }
(1)/src/views/Example/CellStyle/index_2.vue
- <el-table
- border
- size="small"
- row-key="id"
- highlight-current-row
- :data="feats.list"
- :cell-style="handleChangeCellStyle"
- >
- <el-table-column label="评分" width="100" align="center">
- <template slot-scope="scope">
- <el-link type="danger">{{ scope.row.score }}</el-link>
- </template>
- </el-table-column>
- </el-table>
-
- methods: {
- /**
- * 改变表格单元格颜色
- */
- handleChangeCellStyle({row, column, rowIndex, columnIndex}) {
- let cellStyle = {}
- if (row.score > 9) {
- cellStyle.backgroundColor = '#ffdcdc'
- }
- else if (row.score > 7) {
- cellStyle.backgroundColor = '#fde2c2'
- }
- else {
- cellStyle.backgroundColor = '#fff'
- }
-
- if (column.label === '评分') {
- return cellStyle
- }
- },
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。