Javascript Vue.js-多条件类绑定
基于多个条件将类绑定到标记的正确方法是什么 给定这个标记,当试图写入多个条件时,一个条件似乎被另一个条件覆盖Javascript Vue.js-多条件类绑定,javascript,vue.js,vuejs2,vue-component,quasar,Javascript,Vue.js,Vuejs2,Vue Component,Quasar,基于多个条件将类绑定到标记的正确方法是什么 给定这个标记,当试图写入多个条件时,一个条件似乎被另一个条件覆盖 <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':
<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>
将该类属性绑定到名为myClass
的计算属性:
<q-tr
:class="myClass"
>
</q-tr>
这有点道理,但实际上不起作用。我得到错误TypeError:无法读取未定义的属性“row”
我不确定props
应该如何定义,因为它被传递到那里的组件
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'
}
}
}