Vue binds multiple dynamic class methods

When using v-for to loop array elements today, I found that binding multiple dynamic classes to elements has been unsuccessful. Now I will summarize a few methods.

method one

isback can be a variable or a constant. isLike can only be a string, which is a class name, and the class name will be added only when likeClass is true.

<div :class="[isback,{
     
     'isLike':likeClass}]"></div>

Method Two

Both classB and classC are class names, both are strings

<i :class=" { classB: true, classC: isC }"></i>

Method three:

class binds a ternary expression

<i :class="isRed?'class1':'class2'"></i> `

Supongo que te gusta

Origin blog.csdn.net/Maybe_ss/article/details/120270977
Recomendado
Clasificación