I’m not sure if it’s possible but what I’m tying to do is to pass a method name in a variable to grandchild.
On my page there is “topbar” component, which contains “button” component.
// Home.vue
<my-topbar :buttons="buttons"></my-topbar>
data() {
return {
buttons: [
{
type: "icon",
icon: "delete",
label: "delete",
method: "deleteSelections",
},
{
type: "icon",
icon: "upload",
label: "upload",
method: "saveToDatabase",
}
]
};
},
// Topbar.vue
<my-button v-for="(button, index) in buttons" :key="index" :button="button"></my-button>
// Button.vue
<v-btn @click="button.method">
<v-icon v-if="button.type !== 'text'">{{icons[button.icon]}}</v-icon>
<span v-if="button.type !== 'icon'">{{$t(`buttons[${button.label}]`)}}</span>
</v-btn>
My problem is @click=“button.method” part. When I click it, it returns: “TypeError: _vm.button.method is not a function”
I tried these 2 syntax but couldn’t get any result, not even an error in this case:
:on-click="${button.method}"
@click="${button.method}"
I appreciate that if someone can tell me the correct way of doing this. Thanks.