-
Notifications
You must be signed in to change notification settings - Fork 545
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Attr fallthrough behavior #92
Conversation
For class and style bindings, and <template>
<div :class="$attrs.class" :style="$attrs.style">
<!-- How does one easily prevent style and class from also being applied here? -->
<div v-bind:"$attrs">
Foobar
</div>
</div>
</template> Perhaps there needs to be similar flags for |
Specifically, you may often wish to apply all event listeners to a child element... maybe a simple helper that plucks off the listeners from |
@tmorehouse you can create a computed property based on |
@yyx990803 so something like this could be done to omit style/class: export default {
props: {
foo: { type: Boolean, default: false }
},
computed: {
computedAttrs() {
return { ...this.$attrs, style: null, class: null }
}
}
} Although is Similarly, if one wanted the v-on listeners (which are now top level export default: {
computed: {
computedListeners() {
return Object.keys(this.$attrs).reduce((obj, key) => {
if (/^on[A-Z]/.test(key)) {
obj[key] = this.$attrs[key]
}
return obj
}, {})
},
computedAttrs() {
return Object.keys(this.$attrs).reduce((obj, key) => {
if (!/^on[A-Z]/.test(key)) {
obj[key] = this.$attrs[key]
}
return obj
}, {})
}
}
} Perhaps exposing a few utility methods like |
@tmorehouse it does remind me that As for helpers like |
this probably isn't the best approach, and I haven't Vue'd in almost a year so I'm sure I have some syntax wrong.. but could you do something like this? <!-- search-component.vue -->
<template>
<form v-bind="$attrs.form" @submit="search">
<input type="text" v-bind="$attrs.input">
<button type="submit" v-bind="$attrs.button">
Search
</button>
</form>
</template> Usage: <search-component
input="{ name: 'foo', value: searchText }"
form="{ onSubmit: fancySearch }"
/> |
@michaeldrotar I think it should be |
Does this also affect v-slot props? Would listeners be exposed as onXXX props there? |
@cjpearson yes. |
This RFC is now in final comments stage. An RFC in final comments stage means that: The core team has reviewed the feedback and reached consensus about the general direction of the RFC and believe that this RFC is a worthwhile addition to the framework. |
I still like the idea of Perhaps instead of This would follow more closely the template convention of |
This proposal has been replaced by #137. |
This is a follow up of #26, but with much less breakage.
Rendered