Vue 樣式切換及三元判斷樣式關聯操作
阿新 • • 發佈:2020-08-10
假設有需求:
後臺返回狀態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;'"
以上這篇Vue 樣式切換及三元判斷樣式關聯操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。