Vue's v-bind syntax supports dynamically binding classes via anobject syntax. You can conditionally bind multiple classes, and use the : shorthand for v-bind::. The value you bind to class with v-bind can be a string, not just anobject.
For example, you can store the class name in a data string:. Another neat approach is to use the ternary operator to decide which class the element will have:.
Binding HTML Classes
You can also bind the class to an array. Vue will then combine allelements in the array to form the final class binding.
This lets youmix and match string and object syntax in one declaration:.
Vue School has some of our favorite Vue video courses. Their Vue.js Master Class walks you through building a real world application, and does a great job of teaching you how to integrate Vue with Firebase.
Conditional class names in Vue.js
Modified5 years, 1 month ago. I am trying to assign a css class to a span element, whenver it push the EDIT button.
This is my working example in jsfiddle: . BUT it only works, because I check if the title property of the edited object is equal to the title property of the todo object, instead I'd rather check if the two objects are equal.
Unfortunately this breaks my code, whenever I have the same property (e.g.
titles) but different objects. Instead I would like to do something like this, where I check todoeditedTodo.
Non Working Jsfiddle:http://jsfiddle.net/r3nepL7u/1/. How do I check if todo is equal with editedTodo. AND is there a better way, to use the v-class directive, instead of using inline expressions, meaning for more complicated calculations?