Skip to content

Instantly share code, notes, and snippets.

@dabernathy89
Last active June 21, 2018 14:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dabernathy89/e238ec22c2b27ad54c91cbca92c48e7d to your computer and use it in GitHub Desktop.
Save dabernathy89/e238ec22c2b27ad54c91cbca92c48e7d to your computer and use it in GitHub Desktop.
How to wrap a component that uses slots?
<v-server-table
:columns="columns"
:options="mergedOptions"
:name="tableName"
:ref="tableName">
<template slot="beforeFilter">
<slot name="beforeFilter"></slot>
</template>
<template slot="afterFilter">
<slot name="afterFilter"></slot>
</template>
<template v-for="(slot, slot_name) in $slots">
<template :slot="'h__' + slot_name.slice(13)" v-if="slot_name.indexOf('table-header-') === 0">
<slot :name="slot_name"></slot>
</template>
</template>
<template v-for="(slot, slot_name) in $scopedSlots">
<!-- This doesn't work 😭 -->
<template :slot="slot_name.slice(11)" slot-scope="props" v-if="slot_name.indexOf('table-cell-') === 0">
<slot :name="slot_name" v-bind:row="props.row"></slot>
</template>
</v-server-table>
@matthewtrask
Copy link

<!-- <slot :name="slot_name" v-bind:row="props.row"></slot> -->

This works though?

@dabernathy89
Copy link
Author

@matthewtrask turns out that this works:

<template
    v-for="(slot, slot_name) in $scopedSlots"
    :slot="slot_name"
    slot-scope="props">
    <slot :name="slot_name" v-bind="props"></slot>
</template>

But this does not:

<template v-for="(slot, slot_name) in $scopedSlots">
    <template
        :slot="slot_name"
        slot-scope="props">
            <slot :name="slot_name" v-bind="props"></slot>
    </template>
</template>

Guess it's just something internal to how Vue handles scoped slots ¯_(ツ)_/¯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment