ElementUI中el-table不同状态显示不同、显示颜色不同、图标不同

 通过向后台发送请求拿到数据,拿到状态的值分别为0,1,2,判断这三个值0显示已完成,1显示进行中,2显示待办款,显示不同还需要使用不同的颜色显示,并且后面的图标也不同

  <el-table-column property="status" label="状态" width="100" fixed="right">
            <template slot-scope="scope">
              <span :class="formatStatusColor(scope.row.status)"> {
   
   { formatStatus(scope.row.status) }}<i :class="formatIcon(scope.row.status)"></i></span>
            </template>
          </el-table-column>
methods: {
    // 格式化状态显示
    formatStatus(status) {
      if (status === '0') {
        return '已完成'
      } else if (status === '1') {
        return '进行中'
      } else if (status === '2') {
        return '待办款'
      } else {
        return ''
      }
    },
    // 格式化状态显示的颜色
    formatStatusColor(status) {
      if (status === '0') {
        return 'color1'
      } else if (status === '1') {
        return 'color2'
      } else if (status === '2') {
        return 'color3'
      } else {
        return ''
      }
    },
    formatIcon(status) {
      if (status === '0') {
        return 'el-icon-circle-check'
      } else if (status === '1') {
        return 'el-icon-loading'
      } else if (status === '2') {
        return 'el-icon-time'
      } else {
        return ''
      }
    }
  }
<style lang="scss">
// 状态的三种颜色样式
.color1{
  color: #5fb878
}
.color2{
  color: #ffb800
}
.color3{
  color: #c2c2c2
}

</style>

猜你喜欢

转载自blog.csdn.net/kobe_IT/article/details/130221526