Home > Net >  Set dynamic css class on vue,js
Set dynamic css class on vue,js

Time:06-16

I'm trying to set a dynamic class in a vue.js, something like

 <strong :class=`color-${category.level}`>{{ category.name }}</strong>

this html is inside a for loop and I need the category.value on this loop but it's not working

CodePudding user response:

The bound class value should be wrapped by quotes :class='...' or double-quotes : :

<strong :></strong>

CodePudding user response:

Add function in :class in your case

 :

and then in methods

 switchClass(level) {
    return `color-${level}`
  }
  • Related