Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

159
Views
How to add conditions with VUE for classes

it's possible to make conditions with Vue to change add class according to the text loaded on the doom?

I have a list with colors name

<span>yellow</span>
<span>red</span>
<span>grey</span>

I want to make a condition for example if the name text is yellow I want to add class "color_yellow" and so on

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Try like following snippet:

new Vue({
  el: '#demo',
  data() {
    return {
      colors: ['yellow', 'red', 'grey']
    }
  }
})

Vue.config.productionTip = false
Vue.config.devtools = false
.color_yellow {
  color: yellow;
}
.color_red {
  color: red;
}
.color_grey {
  color: grey;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="demo">
  <ul>
    <li v-for="(color, i) in colors" :key="i">
      <span :class="`color_${color}`">{{ color }}</span>
    </li>
</div>

over 4 years ago · Santiago Trujillo Report

0

You may try this

<span :class="color.colorName">{{ color.colorName }}</span>

In css,

.yellow { color: yellow }
.red { color: red }

For more details, you can check https://vuejs.org/v2/guide/class-and-style.html

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!