欢迎来到代码驿站!

当前位置:首页 >

Vue 样式切换及三元判断样式关联操作

时间:2020-08-09 11:00:06|栏目:|点击:

假设有需求:

后台返回状态1:启用,0:禁用

1、若要使启用为绿色,禁用不添加其他样式

 <el-table-column
  prop="statusName"
  align="center"
  label="状态">
  <template slot-scope="scope">
  <div :class="{active:scope.row.status==1}">
  {{ scope.row.statusName }}
  </div>
  </template>
  </el-table-column>
 .active{
 color:green;
 }

1、若要使启用为绿色,禁用为红色,可使用三元表达式绑定样式

 <el-table-column
  prop="statusName"
  align="center"
  label="状态">
  <template slot-scope="scope">
  <div :class="scope.row.status==1? 'active':'native'">
  {{ scope.row.statusName }}
  </div>
  </template>
  </el-table-column>
.active{
 color:green;
 }
 .native{
 color:red;
 }

补充知识:vue通过判断写样式(v-bind)

如下所示:

v-bind:style="$index % 2 > 0?'background-color:#FFF;':'background-color:#D4EAFA;'"

上一篇:Java判断字符串是否为IP地址的方法

栏    目:

下一篇:R语言ggplot2边框背景去除的实现

本文标题:Vue 样式切换及三元判断样式关联操作

本文地址:http://www.codeinn.net/misctech/3297.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有