[Vuejs]-How to conditionally add attributes in vue.js?

0👍

In Vue.js attributes or bindings can be set dynamically by using v-bind directive.

For example above it can be presented as a computed property:

computed: {
  dialogBindings () {
    if (!this.is_mobile) {
      return {
        fullscreen: true,
        hideOverlay: true,
        transition: 'dialog-bottom-transition'
      }
    }
    return {}
  }
}

And used inside component’s template:

<v-dialog   
  v-model="data_table.dialog"
  v-bind="dialogBindings"
>

Leave a comment