Home > Enterprise >  How to use if/else condition in html table td
How to use if/else condition in html table td

Time:08-27

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
}

CodePudding user response:

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

<td : 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