[Vuejs]-Vue: call a parent function from child with extra param

0๐Ÿ‘

I would do it using data attributes.

First, add $event param to sort method. this would be the event object for the click event.

<AqTableHeader @click="sort('name',$event)" text="Name" />

in AqTableHeader, add a data attributes for isAsc

<template>
    <th :class="{small: checkbox}" v-on="$listeners" :data-is-asc="isAsc">
        <!-- ... -->
    </th>
</template>

and in sort method, get isAsc using the event parameter

    sort(type,$event) {
        const isAsc = $event.target.dataset.isAsc;
        // ... other logic
    }
๐Ÿ‘คJacob Goh

Leave a comment