I
I
Igor2021-03-31 13:38:18
Vue.js
Igor, 2021-03-31 13:38:18

How to inherit slots in Vue?

How to inherit slots in Vue?
We use Vuetify components.

We want to add the ability to save column widths in v-data-table.

To achieve this goal, we want to make a wrapper component for v-data-table
But how can we inherit all slots and props without verbose?
In order to use it in the future as a normal v-data-table.

I assume that the entire family will need to be wrapped and styled as a component.
v-data-table
v-data-table-header
v-data-footer
v-edit-dialog
v-simple-checkbox

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Romanov, 2021-03-31
@IgorPI

<template>
    <v-data-table>
        <template v-for="(_, slot) of $slots" :slot="slot">
            <slot :name="slot"/>
        </template>

        <template v-for="(_, slot) of $scopedSlots" #[slot]="scope">
            <slot :name="slot" v-bind="scope"/>
        </template>
    </v-data-table>
</template>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question