Hi, I’m trying to achieve something like this:
<component :is="someComp" v-bind="compProps" :someProp="someValue"></component>
So far so good…except for any bindings, events and such, which would be unknown (as well as props and attrs) so I can’t hardcode it into the template (as in the example above).
I guess I’m trying to achieve something like this:
(everything in an object defined somewhere else, retrieved from a server, etc)
{ prop1: 'foo1', prop2: 'foo2', ':class': 'item.class', }
But of course v-bind with an object only works for props and attrs.
So far I’ve tried:
- v-bind: as stated above, only works for props and attrs
- a custom directive: creating any corresponding vnodes and attaching them, couldn’t manage to actually append any child vnodes
- an async component, but of course, by the time of defining it’s template, I don’t have any props nor attrs to actually do anything interesting
Also, about point 2, a custom directive and/or working with the virtual DOM, I don’t know how complex or not any binding expressions might be, so having to parse and apply them manually is kinda reinventing the wheel…
How to achieve something like this ?
What’s the best/propper/elegant way to achieve this?
Update: I’ve managed to do this through a custom component that wraps an async custom component, which gave me (initially) the same issue of not having props to know what should be the template for the async comp, but by chance discovered that I could hook myself into “beforeCreate” (on the static comp) and there define the async comp (instead of defining it directly in the “components” option of the Component Options object, and it worked just perfectly…
But I’m not sure if this is actually the propper way to achieve this, it works marvelously, but feels kinda hacking my way around rather than “the Vue way to do this”…
Any thoughts?