formatter使用

767 阅读1分钟

用来格式化内容,大家在开发项目都会碰到,下面就来讲讲formatter 希望这些经验能在开发的过程中帮助到大家!!!

咱先来看看数据和展示效果

处理方式:过滤或处理数据

本节主要讲讲 elementui 框架 formatter处理

  <el-table-column
    prop="checkStatus"
    :formatter="({checkStatus}) => formatting(checkStatus, SpotCheckStatus)"
    sortable
    label="抽查状态"
    width="150px"
  >

  data () {
    // 这里存放数据
    return {
	  SpotCheckStatus: [
        { label: '全部', value: '' },
        { label: '未抽查', value: '0' },
        { label: '省级已抽查', value: '1' },
        { label: '市级已抽查', value: '2' },
        { label: '各级均已抽查', value: '3' }
      ],
    }
  }
  
  methods: {
    // 格式化 处理一个table表多个转换
    formatting (cell, column) {
      if (cell === null) return '-'
      const result = column.find(item => +item.value === +cell || item.value === cell)
      return result ? result.label : '-'
    }
  }

希望能帮助到大家,同时祝愿大家在开发旅途中愉快!!!

拿着 不谢 请叫我“锤” !!!