Vue+ElementUI动态显示el-table某列(值和颜色)的方法
方法一:结合 template scope组件和 v-if 语法判断
例1:值
<el-table-column prop="status" label="车辆状态">
<template scope="scope">
<span v-if="scope.row.status=== 1">在线</span>
<span v-else-if="scope.row.status=== 0">离线</span>
</template>
</el-table-column>
例2:值和颜色
<el-table-column prop="breakdownGrade" label="故障等级">
<template scope="scope">
<span v-if="scope.row.breakdownGrade=== '0'" style="color: #909399">轻微故障(一级)</span>
<span v-else-if="scope.row.breakdownGrade=== '1'" style="color: #e6a23c">⼀般故障(⼆级)</span>
<span v-else-if="scope.row.breakdownGrade=== '2'" style="color: #f56c6c ">严重故障(三级)</span>
</template>
</el-table-column>
方法二:使用 Element-ui formatter属性 v-bind 绑定
<el-table-column
prop="status"
align='center'
label="车辆状态"
:formatter="formatStatus">
</el-table-column>
formatStatus(row, column) {
return row.status == '0' ? '在线' : '离线'
}
方法三:在 data 对象中绑定属性并结合 el-tag 标签
- 在 data 中定义相关值
data () {
return {
carStatus: {
'used': { 'status': '使用中', 'type': 'primary' },
'noused': { 'status': '未使用', 'type': 'info' },
'broken': { 'status': '故障', 'type': 'danger' },
'trash': { 'status': '废弃', 'type': 'warning' }
}
}
}
- 在 template 中使用
<el-table-column prop='status' label='车辆使用状态'>
<template slot-scope="scope">
<div slot="reference" class="carUsedCondition">
<el-tag :type="carStatus[scope.row.status].type">
{{carStatus[scope.row.status].status}}
</el-tag>
</div>
</template>
</el-table-column>
新手学习,如有不妥之处,欢迎指正!
Vue+ElementUI动态显示el-table某列(值和颜色)的方法的更多相关文章
- treeview自动从表中添加标题和列值做目录的方法2
treeview自动从表中添加标题和列值做目录的方法2,该方法是借鉴万一老师的 http://www.cnblogs.com/del/archive/2008/05/15/1114450.html 首 ...
- element-ui 中的table的列隐藏问题
element-ui 中的table和bootstrap中的table的某些设置还是有一定的差别的.之前用bootstrap做的表格,想要实现简短列和详细列的切换.因为详细列实在有太多列了,拉动滚动条 ...
- ASP.new GridView获取隐藏列值的几种方法
解决方法: 原文来自:http://www.tzwhx.com/NewShow/newBodyShow/控件_32933.html 作者:lerit 1.隐藏列前获取数据 看这样一个例子(以下均以此 ...
- vue element-ui 用checkebox 来模拟选值 1/0
https://jsfiddle.net/57dz2m3s/12/ 复制 粘贴 打开url就可以看到效果
- ORACLE列值合併
合併列值最通用的方法就是寫一個自定義函數去實現,這裏介紹的是其它方法. 在SQL Server中合併列值能够使用For Xml Path,在Oracle中則能够使用wm_concat 或 ListAg ...
- 关于同一密码使用generate_password_hash生成不同的密码散列值
在python的 werkzeug.security 库中有两个函数generate_password_hash与check_password_hash用于对密码明文生成散列值以及检查密码是否与提供的 ...
- vue中对element-ui框架中el-table的列的每一项数据进行操作
vue中使用element table,表格参数格式化formatter 后台返回对应的数字, 那肯定不能直接显示数字,这时候就要对 表格进行数据操作 如图: 代码: methods: { //状态改 ...
- excel转化为table(去掉所有列值都为空的值一行,即返回有效值的DataTable)
/// <summary> /// 去掉所有列值都为空的值一行,即返回有效值的DataTable /// </summary> /// <param name=" ...
- jQuery动态对表格Table进行添加或删除行以及修改列值操作
jQuery,不仅可以以少量的代码做很多操作,而且兼容性好(各种浏览器,各种版本). 下面用jQuery动态对表格Table进行添加或删除行以及修改列值操作 1.jQuery代码 <script ...
- jQuery获取Table某列的值
在写此篇博文时,发现在以前曾写过<获取DataTable选择第一行某一列值>http://www.cnblogs.com/insus/p/5434062.html . 但是与此篇所说的完全 ...
随机推荐
- win10下载jdk并配置环境变量
win10下载jdk并配置环境变量 1. jdk下载 下载官网:Java SE开发套件15.0.2 2. jdk安装 一直点下一步就可以 3. 环境变量 配置 右键我的电脑--属性--高级系统设置-- ...
- ubuntu 安装错误解决
1. ubuntu 安装错误解决: Preparing to unpack .../apport_2.20.9-0ubuntu7.15_all.deb .../var/lib/dpkg/info/ap ...
- 在CentOS7中安装Redis
一.检查操作系统中是否安装gcc依赖 [root@192 bin]# yum list installed gcc 如果出现上面图片内容则是已经安装.(由于我是安装了的,所以会存在) 二.安装gcc- ...
- 在开启hadoop时候报错:localhost: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
此时 ssh localhost也会失败 原因是秘钥没有给自己, 运行ssh-copy-id -i ~/.ssh/id_rsa.pub root@localhost 即可解决.
- Delphi书籍大全【阿里云盘】
「marco cantu的Object Pascal Handbook」等文件 https://www.aliyundrive.com/s/sJtUo8ziUpV 提取码: 5tp6点击链接保存,或者 ...
- xShell执行js脚本
var CMD = 'ls'; var INTERVAL = 1; var MAX = 5; var CR = String.fromCharCode(13); var LF = String.fro ...
- 解决IOS上传竖向照片会旋转90度的问题
// 解决IOS上传竖向照片会旋转90度的问题 rotate() { const that = this; that.imgOrientation = 1; let Orientation = nul ...
- 记录搜索的例子 浙大c
#include <stdio.h> struct{ int amount; char *name; } coins[] = { {1, "penny"}, {5, & ...
- Vue3 animate.css + wowjs 官网实现滚动到对应元素位置增加动画特效
本人在Vue3中使用的是 setup语法糖 也就是 <script setup>...</ script> 在项目中install一下两个插件: yarn add animat ...
- java的3中代理模式
代理模式是什么 代理模式是一种设计模式,简单说即是在不改变源码的情况下,实现对目标对象的功能扩展. 比如有个歌手对象叫Singer,这个对象有一个唱歌方法叫sing(). 1 public class ...