I want to create components in a loop, passing properties to the child by name.
so:
<card-base v-for="(card, i) in cards" :key="i" :heading="card.heading" :width="card.width" class="dashboard-card" :cardHeaderButtons="[{icon: 'minimize', fn: 'minimizeDashboardCard'}]">
in my (child!) component i have defined the minimizeDashboardCard method,
and
<v-btn icon flat class="header-button" v-for="(button, i) in cardHeaderButtons"
:key="i"
v-if="$vuetify.breakpoint.lgAndUp"
color="white"
@click.capture.stop="button.fn"
>
<v-icon>
{{ button.icon }}
</v-icon>
</v-btn>
the {{ button.icon }} works. but the fn doesn't
Uncaught TypeError: button.fn is not a function
at !click (CardBase.vue?ac7a:32)
at invoker (vue.esm.js?efeb:2027)
at HTMLButtonElement.fn._withTask.fn._withTask (vue.esm.js?efeb:1826)
i also tried with this[button.fn], but that doesn't work either.
the solution is probably super easy, but i don't see it right now. how can i pass the method NAME? (like for minimize, i want to have methods defined once in that card component and just have to pass the name to reuse it.)
thanks :)
button.fnis defined as a string. IfminimizeDashboardCardis a method in the parent scope, just pass the function.fn: minimizeDashboardCardminimizeDashboardCardis only defined in the child. that's why i want to pass strings and not define the "minimize" method in every place i use it around the app. (edited the original question to make it clear the method is only defined in the child method)