热门标签 | HotTags
当前位置:  开发笔记 > 前端 > 正文

vueelementui中的table针对于一列中不同的数据添加不同的样式

针对table中的row中的值给出不同的样式解决方案;1.在标签中添加属性;实例

针对table中的row中的值给出不同的样式

 解决方案;

    1.在标签中添加属性 ;

      实例

      
            :data="tableData"

            

            

            @selection-change="handleSelectionChange"

            :row-class-name="tableRowClassName"

          >

    2.利用这个函数进全局的循环,循环出所有的数据进行匹配,返回一个class名称,根据不同的名称,更改不同的样式  

      tableRowClassName({row, rowIndex} ){

            for(let i=0; i
                  if(this.tableData[i].jobState =="字段1"){

                      return 'redStyle'

                  }else if(this.tableData[i].jobState =="字段2"){

                      return 'greenStyle'

             

                  }else if(this.tableData[i].jobState =="字段3"){

                      return 'blueStyle'



                  }else if(this.tableData[i].jobState =="字段4" || this.tableData[i].jobState =="字段5"){

                      return 'orangeStyle'

                  }

              }

        },

 

    字段1,字段2,字段3,字段4,字段5 就需要进行匹配的字段名称

  

    redStyle ,greenStyle,blueStyle,orangeStyle 是class名称

 

    

    ::v-deep .redStyle{

        .el-table__cell{

         &:nth-of-type(2){ color: #ff5400 !important;}

            &:nth-of-type(3){ color: #FF1717 !important;}

            &:nth-of-type(6){ color: #ccc !important;}

        }

      }

    ::v-deep .greenStyle{

      .el-table__cell{

          &:nth-of-type(2){ color: #0CD09C  !important;}

          &:nth-of-type(3){ color: #0CD09C  !important;}

          &:nth-of-type(6){ color: #0CD09C  !important;}

       }

    }

    ::v-deep .blueStyle{

        .el-table__cell{

          &:nth-of-type(2){ color: #5231FF !important;}

          &:nth-of-type(3){ color: #5231FF !important;}

          &:nth-of-type(6){ color: #5231FF !important;}

        }

    }

    ::v-deep .orangeStyle{

       .el-table__cell{

          &:nth-of-type(2){ color: #FF9500 !important;}

          &:nth-of-type(3){ color: #FF9500 !important;}

          &:nth-of-type(6){ color: #FF9500 !important;}

        }

    }

    

 



推荐阅读
author-avatar
Ocean哔哔芭比波哔
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有