vue bind class on condition code example

Example 1: bind style with condition in vue

<figure :style="[item.main_featured ? {'background': 'url(' + item.main_featured + ') center no-repeat'} : {'background': '#FFF'}]">

Example 2: vue if echo class

<div class="defaultclass" :class="condition?' conditionalclasstoappend':''"></div>

Example 3: vue class binding if else

vue class binding if else
<div :class="{ 'prop-name': boolVar }"></div>
:class="darkMode ? 'dark-theme' : 'light-theme'"
If darkMode is true, we apply dark-theme as our class name. 
	Otherwise we choose light-theme.

Tags:

Html Example