Vue 樣式切換及三元判斷樣式關聯操作
假設有需求:
后臺返回狀態1:啟用,0:禁用
1、若要使啟用為綠色,禁用不添加其他樣式
<el-table-column prop='statusName' 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' 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 樣式切換及三元判斷樣式關聯操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。
相關文章: