2

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
}
5
  • Specify the language please Commented Aug 27, 2022 at 4:12
  • And also tell, what exactly you want to do Commented Aug 27, 2022 at 4:15
  • I have reference for you, may it helps :) stackoverflow.com/questions/502431/… Commented Aug 27, 2022 at 4:17
  • I am using vue typescript, I want to show if the data is 'NW' then the <td> will become color red. else the <td> will become blue. @AsaduzzamanAtik thanks Commented Aug 27, 2022 at 4:18
  • Tryout my answer Commented Aug 27, 2022 at 4:34

3 Answers 3

2

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

Sign up to request clarification or add additional context in comments.

2 Comments

Cool, it's worked well. the text color changed, can the class also changed the background-color also?
Yes, you can!...
1

You can use the alternative method below:

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

Comments

0

Try with below code

<th:block th:if="${item.cStatus == 'NW'}">
<td data-label="Status" style="color:red;">{{$t('Status'+item.cStatus)}}</td>
</th:block>
<th:block th:unless="${item.cStatus == 'NW'}">
<td data-label="Status" style="color:blue;">{{$t('Status'+item.cStatus)}}</td>
</th:block>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.