服务器之家:专注于服务器技术及软件下载分享
分类导航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服务器之家 - 编程语言 - JavaScript - Vue 样式切换及三元判断样式关联操作

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

2021-08-12 17:33web coder JavaScript

这篇文章主要介绍了Vue 样式切换及三元判断样式关联操作,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧

假设有需求:

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

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

?
1
2
3
4
5
6
7
8
9
10
11
12
13
<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、若要使启用为绿色,禁用为红色,可使用三元表达式绑定样式

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<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;'"

以上这篇Vue 样式切换及三元判断样式关联操作就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/xuerwang/article/details/84065734

延伸 · 阅读

精彩推荐