I am currently using Vue-datatable, where I have a generic vue component as . I am using this base component to render data table and I have a @click event in the in the element. but as I use this component in various places I want the @click event to be overridden so that, I could call the diffenent method as per my need.
the below file is BaseTable.vue
<v-app id="inspire">
<v-data-table
v-model="selected"
:headers="headers"
:items="desserts"
:pagination.sync="pagination"
select-all
item-key="name"
class="elevation-1"
>
<template v-slot:headers="props">
<tr>
<th>
<v-checkbox
:input-value="props.all"
:indeterminate="props.indeterminate"
primary
hide-details
@click.stop="toggleAll"
></v-checkbox>
</th>
<th
v-for="header in props.headers"
:key="header.text"
:class="['column sortable', pagination.descending ? 'desc' : 'asc', header.value === pagination.sortBy ? 'active' : '']"
@click="changeSort(header.value)"
>
<v-icon small>arrow_upward</v-icon>
{{ header.text }}
</th>
</tr>
</template>
<template v-slot:items="props">
<tr :active="props.selected" @click="props.selected = !props.selected">
<td>
<v-checkbox
:input-value="props.selected"
primary
hide-details
></v-checkbox>
</td>
<td>{{ props.item.name }}</td>
<td class="text-xs-right">{{ props.item.calories }}</td>
<td class="text-xs-right">{{ props.item.fat }}</td>
<td class="text-xs-right">{{ props.item.carbs }}</td>
<td class="text-xs-right">{{ props.item.protein }}</td>
<td class="text-xs-right">{{ props.item.iron }}</td>
</tr>
</template>
</v-data-table>
</v-app>
</template>```
Could I possibly override the triggercall method shown above in the code?
Thanks.
Trigger an
eventfrom your component, which can be listened from the parent component.Let say in your
DataTablecomponent there isbuttonwhich triggers aclick:Now where you want to use
DataTablecomponent and want to execute amethodwhen someone clicks the button which is insideDataTablesimply -
In case you want to have
methodinside the component and can override that from parent. Then this is the optional behaviour you want- It's like you want to create a which behaves globally.You need to have an extra
propto tell your global component that you want method to be overridden by a parent method.So by default you will execute your default
methodbut if you passparentHandler= trueto component it will execute the parent method