How to use if/else condition in html table td

Viewed 70

I want to ask how can I doing if/else condition in this tag?

 <td data-label="Status">{{$t('Status'+item.cStatus)}}</td>

What I want is

if(item.cStatus == NW){
color:red
}
else{
color:blue
}
1 Answers

You can pass an object to :class (short for v-bind:class) to dynamically toggle classes:

<td :class="[item.cStatus == NW ? 'red' : 'blue']" data-label="Status">{{$t('Status'+item.cStatus)}}</td>

The above syntax means the presence of the red class will be determined by the truthiness of the data property item.cStatus == NW.

Then you can add your desired style to red or blue class


You can also do it by :style object


You can find more details here

Related