5
私のコンポーネントに値を設定せずに属性を設定したい。たとえば:値を持たないVueコンポーネントの小道
<my-button primary>Save</my-button>
私は私のコンポーネントのprops
にprimary
を宣言しています:
Vue.component("my-button", {
props: ["primary"],
template: "<button v-bind:class='{primary: primary}'><slot></slot></button>"
})
残念ながら、それは動作しません。 primary
プロパティはundefined
であり、クラスは適用されません。
JSFiddle:
は次に指定するだけで名前がtrue
に設定し、その値になります属性:
https://jsfiddle.net/LukaszWiktor/g3jkscna/
クレジット[@Mottokrosh](https://stackoverflow.com/users/1244894/mottokrosh)に彼はもともとlaracasts議論でこの解決策を掲載さ:値なし [小道具(だと思います(https://laracasts.com/discuss/channels/vue/props-without-values-think-attributes-in-vuejs)を参照してください。 –