表格中的状态类型值(tag)

一:数字转换为简单的中文值
在这里插入图片描述

** 不用转换直接用find()方法:在statusList里找;
**lastHandleCode是对应的获取到的每行数据的code值;

vue:


      <el-table-column label="执行状态" align="center">
        <template slot-scope="scope"> {{ statusList.find(t => t.value === scope.row.lastHandleCode).label }}</template>
      </el-table-column>

data()


      statusList: [
        { value: 500, label: '失败' },
        { value: 502, label: '失败(超时)' },
        { value: 200, label: '成功' },
        { value: 0, label: '无' }
      ],

二:转换为标签
在这里插入图片描述

主要是:formatter=“statusFormatter”

<el-table-column label="设备占用状态" :show-overflow-tooltip="true"  align="center" prop="inUse" sortable :formatter="statusFormatter"></el-table-column>

data()

      // 状态数据字典
      statusOptions: [{id: 1,itemValue : '占用',itemText : '1'},{id: 2,itemValue : '空闲',itemText : '0'}],

js:

  created() {
    this.statusFormatter()
  },
methods:{
// 设备占用状态
    statusFormatter(row, column, cellValue, index) {
      const dictLabel = this.selectDictLabel(this.statusOptions, cellValue)
      if (cellValue == '0') {
        return <el-tag type='success'>{dictLabel}</el-tag>
      } else if (cellValue == '1') {
        return <el-tag type='warning'>{dictLabel}</el-tag>
      } else {
        return <el-tag>{dictLabel}</el-tag>
      }
    }
}

这里的this.selectDictLabel是提前写好的一个方法,在main.js引入全局使用:

import { selectDictLabel } from '@/utils/data-process'

Vue.prototype.selectDictLabel = selectDictLabel

在文件 /utils/data-process里:

// 回显数据字典
export function selectDictLabel(datas, value) {
  var actions = []
  Object.keys(datas).map((key) => {
    if (datas[key].itemText === ('' + value)) {
      actions.push(datas[key].itemValue)
      return false
    }
  })
  return actions.join('')
}

相关推荐

  1. C#类型和引用类型区别

    2024-03-28 05:10:03       33 阅读
  2. 深入理解 Golang 类型和引用类型

    2024-03-28 05:10:03       68 阅读
  3. C#类型和引用类型

    2024-03-28 05:10:03       47 阅读
  4. go方法Receiver (类型&指针类型

    2024-03-28 05:10:03       47 阅读
  5. C#类型与引用类型

    2024-03-28 05:10:03       29 阅读
  6. 信号状态类型

    2024-03-28 05:10:03       48 阅读
  7. React 状态管理类型错误及解决方案

    2024-03-28 05:10:03       59 阅读
  8. jsSymbol强制类型转换

    2024-03-28 05:10:03       39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-03-28 05:10:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-03-28 05:10:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-03-28 05:10:03       87 阅读
  4. Python语言-面向对象

    2024-03-28 05:10:03       96 阅读

热门阅读

  1. 【前端学习——css篇】2.css选择器的优先级

    2024-03-28 05:10:03       48 阅读
  2. hive 、spark 、flink之想一想

    2024-03-28 05:10:03       37 阅读
  3. dfs (蓝桥备赛)

    2024-03-28 05:10:03       34 阅读
  4. React系列之React版本时间线和主要更新

    2024-03-28 05:10:03       45 阅读
  5. Unity3D 制作MMORPG 3D地图编辑器详解

    2024-03-28 05:10:03       45 阅读
  6. 【无标题】

    2024-03-28 05:10:03       43 阅读
  7. 内核态转发平面的SSL加速

    2024-03-28 05:10:03       42 阅读
  8. Spring_MVC

    2024-03-28 05:10:03       40 阅读