search

Home  >  Q&A  >  body text

How to get Vue component data when setup using script

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 combination script settings, So I managed to get

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

But how do I get the data? Start with this part -> render(h, { props, slot, data }) {

The data should contain domProps if there is 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

P粉392861047P粉392861047375 days ago373

reply all(1)I'll reply

  • P粉707235568

    P粉7072355682024-01-17 10:30:01

    If you still need this,

    useSlots().default() Returns slot data, including DOM attributes.

    reply
    0
  • Cancelreply