The Class property in Vue.js allows dynamic addition or removal of CSS classes. Its value is an object, the key is the CSS class name, and the value is a Boolean value. When the value corresponding to the key is true, the corresponding CSS class is applied to the element; when the value corresponding to the key is false, the corresponding CSS class is removed from the element. Multiple CSS classes can be specified with spaces.
Class attribute in Vue.js
What is the Class attribute?
The class
property in Vue.js allows dynamically adding or removing CSS classes on HTML elements.
Usage:
<code><div :class="{ active: isActive, disabled: isDisabled }"></div></code>
Structure:
class
The value of the attribute is an object, where :
Dynamic application CSS class:
If the values corresponding to the object's keys (isActive
and isDisabled
) are true
, then the corresponding CSS class (active
and disabled
) will be applied to the element.
Remove CSS classes:
When the value corresponding to the key of the object is false
, the corresponding CSS class will be removed from the element .
Multiple CSS classes:
Multiple CSS classes can be specified as object keys by using spaces:
<code><div :class="{ 'class-1': condition1, 'class-2': condition2 }"></div></code>
Note:
class
The value in the attribute must be an object. true
or false
. The above is the detailed content of How to use classes in vue. For more information, please follow other related articles on the PHP Chinese website!