Skip to content

Instantly share code, notes, and snippets.

@Tanimodori
Created October 14, 2022 08:00
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 Tanimodori/1c6beea07aeac1377584e27c7cd4b2dd to your computer and use it in GitHub Desktop.
Save Tanimodori/1c6beea07aeac1377584e27c7cd4b2dd to your computer and use it in GitHub Desktop.

ScopedSlotsProxy.vue

<script lang="ts">
  import { defineComponent, h } from 'vue';

  export default defineComponent({
    name: 'ScopedSlotsProxy',
    props: ['as', 'scopedSlots'],
    setup(props, { attrs, slots }) {
      const { as, scopedSlots, ...rest } = props;
      return () =>
        h(as ?? 'div', {
          attrs,
          props: rest,
          scopedSlots: {
            ...slots,
            ...scopedSlots,
          },
        });
    },
  });
</script>

Usage: ProxyTable.vue

<template>
  <ScopedSlotsProxy
    :as="Table"
    :scopedSlots="$scopedSlots"
    v-bind="$attrs"
  />
</template>
<script lang="ts" setup>
  import { Table } from 'ant-design-vue';
  // more code
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment