From an exernal source (for example api), I get a component definition:
{
"component": "b-btn",
"content": "Button",
"attr": {
"title": "Edit"
},
"events": {
"click": "doSomething"
}
}
This definition is used with a dynamic component:
<component :is="item.component" v-bind="item.attr">
{{ item.content }}
</component>
and it works as expected (a vue-bootstrap button is shown, with the title 'Edit' and a button text 'Button').
Now I want to add events as well. Since VueJS 2.4 (https://vuejs.org/v2/api/#v-on), you can define events in object syntax like <button v-on="{ mousedown: doThis, mouseup: doThat }"></button>, I thought, just adding v-on="item.events" might work:
<component :is="item.component" v-bind="item.attr" v-on="item.events">
{{ item.content }}
</component>
But it doesn't, since the value of the object property click is a string ("doSomething") and not a callable.
// Just to make it clear
{"click": "doSomething"} != {"click": doSomething}
Is there any way to bind dynamic events (from JSON) to a component?
this["doSomething"](), but is "doSomething" already defined in the method's object of the Vue instance? Or where is it defined? - Ricky