问题描述
鉴于此标记,似乎在尝试编写多个条件时一个条件被另一个条件覆盖。
<q-tr :props="props"
:class=["(props.row.Name=='Row Name 1' || props.row.Name=='Row Name 2')?'text-bold':'bg-white text-black',(props.row.Name=='Row Name 3')?'text-green':'bg-white text-black']
>
</q-tr>
因此在上面的示例中,text-bold
类被bg-white text-black
覆盖,因为第二个条件覆盖了第一类绑定。
在vue类绑定中,有没有办法以if,else if,else
样式构造条件?
解决方法
将该类属性绑定到名为myClass
的计算属性:
<q-tr
:class="myClass"
>
</q-tr>
computed:{
myClass(){
if(this.props.row.Name=='Row Name 1' ){
return 'text-bold';
}
else if( this.props.row.Name=='Row Name 3'){
return 'text-green';
}
else{
return 'bg-white text-black'
}
}
}