Closed yzx9 closed 4 years ago
The motivation part is, to me, way too short given the small improvement this brings.
Even though, this can just be a helper function:
import { resolveComponent, h } from 'vue'
function fixedProps(component, propsData) {
// this example is missing how things should be properly passed, but it doesn't change much
return () => h(typeof component === 'string' ? resolveComponent(component) : component, {...propData}, children)
}
and then use that:
components: {
Card: fixedPropd(Card, { shadow: 'hover' })
}
So I don't think there is a need to add another api for components
@posva how'd you do that with components that are already registered (i.e. coming from some lib) and you want to set default props globally and not just within one components
object?
@jacekkarczmarczyk with resolveComponent
to retrieve the component, which could be done by the function itself if it gets a string (I updated the example)
Maybe I wasn't clear enough, I meant that I don't want to use components
option for components that are registered globally. Imagine for example I want exaxt
prop of a router-link
to be always true, without need of adding it to components
option as it is done in your example
I'd better go with a component wrapping for this one. It's already an established practice and works perfectly fine. Could you please expand on why component wrapping doesn't fit you and how this proposal fixes the issue?
Seems implement this feature as a lib is the better way.
Provide default props on component registration when define component.
Rendered