I have a component which shows a list. This list is dynamically populated by pages using this component.
<template>
<v-list
subheader
>
<v-subheader class="font-weight-black">Choose action</v-subheader>
<v-divider/>
<v-list-item
v-for="(item, i) in model.menu"
:key="i"
@click="item.action"
>
<v-list-item-title>{{ item.title }}</v-list-item-title>
</v-list-item>
</v-list>
</template>
And this is the TypeScript class.
<script lang="ts">
import { Component, Vue, Watch, Prop } from 'vue-property-decorator'
import { app } from 'electron'
@Component
export default class ListItem extends Vue {
@Prop() appStatus!: string
@Prop() appId!: string
model: any = {
menu: [
{ title: 'Title One', action: 'someModalAction(appId)' },
{ title: 'Title Two', action: '' },
{ title: 'Title Three', action: '' }
]
}
someModalAction( appId: string ) {
// show some modal here
}
</script>
Here model object would be dynamic and other pages would pass this object as Prop() (This is just an example here).
When I click on Title One, nothing happens. However, when I change the object to
{title: 'Title One', action: this.someModalAction(this.appId)}
Then I can see the modal when the page is loaded. When I close this modal, the list item cannot be clicked then.
So, how can I pass actions to @click dynamically?
@click="item.action()"?@click=item.action(i)since there is a parameter appId?iis just the index here. I was hoping to just put this string'someModalAction(appId)'in @click, but somehow that doesn't work.