没有值的Vue组件道具
问题描述:
我想在我的组件上设置一个没有任何价值的属性。例如:没有值的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
,该类不适用。
答
贷[@Mottokrosh(https://*.com/users/1244894/mottokrosh),因为他原先张贴在laracasts讨论此解决方案:无值 [道具(想属性)在Vuejs](https://laracasts.com/discuss/channels/vue/props-without-values-think-attributes-in-vuejs)。 –