Skip to content

Instantly share code, notes, and snippets.

@fanghm
Created October 12, 2017 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fanghm/1b0fe69721878bde91d7852d6c98cab7 to your computer and use it in GitHub Desktop.
Save fanghm/1b0fe69721878bde91d7852d6c98cab7 to your computer and use it in GitHub Desktop.
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