How to implement conditional class binding in VUE
P粉099985373
P粉099985373 2024-03-29 19:17:07
0
1
293

Is it possible to create a condition using Vue to add a class based on the text loaded on the doom changes?

I have a list with color names

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

I want to set a condition, for example if the name text is yellow I want to add the class "color_yellow" etc.

P粉099985373
P粉099985373

reply all(1)
P粉627136450

Try a code snippet like the following:

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;
}
sssccc
  • {{ color }}
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!