Vue component components without value

I want to set an attribute on my component without any value. For example:

<my-button primary>Save</my-button>

I declare primaryin propsmy component:

Vue.component("my-button", {
  props: ["primary"],
  template: "<button v-bind:class='{primary: primary}'><slot></slot></button>"
})

Unfortunately, it does not work. The property primaryis undefined, and the class does not apply.

JSFiddle: https://jsfiddle.net/LukaszWiktor/g3jkscna/

+6
source share
1 answer

The key is to declare the type of support as Boolean:

props: {
    primary: Boolean
}

Then, specifying only the attribute name makes its value equal true.

Working JSFiddle: https://jsfiddle.net/LukaszWiktor/gfa7gkdb/

+10
source

All Articles