hawk_lv
hawk_lv

Reputation: 23

How I can get Vue component data while using script setup

I need to rewrite this code

export default Vue.extend<Props>({
  functional: true,
  render(h, { props, slots, data }) {
    const { href, external, target, type, button } = props;
    const slot = slots().default;
    console.log(data);
    ....

to Vue 3 Composition script setup, So I managed to get

<script setup lang="ts">
 import {h, useSlots} from 'vue';
 const props = defineProps<Props>();
 const slots = useSlots();
 ...

But how I can get data ? from this part -> render(h, { props, slots, data }) {

data should contain domProps if have such.. etc

console.log(data);

{
    {                                                                                                                                                                                                                                   
  attrs: {
    target: '_self',
    href: 'https://example.com',
    button: true
  },
  class: [
    'X-button',
    {
      'X-button--': false,
      'X-button--size-auto': true
    }
  ]
}

Thanks in advance

Upvotes: 1

Views: 1360

Answers (1)

octaviandd
octaviandd

Reputation: 179

If you still need this,

useSlots().default() returns the data for the slots, including the DOM props.

Upvotes: 1

Related Questions