Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Style binding

v-bind:class

<div v-bind:class="classObject"></div>

data: {
  isActive: true,
  error: null
},
computed: {
  classObject: function () {
    return {
      active: this.isActive && !this.error,
      'text-danger': this.error && this.error.type === 'fatal'
    }
  }
}

putting classes in an array

<div v-bind:class="[isActive ? activeClass : '', errorClass]"></div>

v-bind:style

<div v-bind:style="{ color: activeColor, fontSize: fontSize + 'px' }"></div>
<div v-bind:style="[baseStyles, overridingStyles]"></div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment