2021年5月6日星期四

How to get HTMLElement from child component in slot?

How can I get the Dom element of the child in slot. Attempts to get in the life hook onMounted () the el vnode property of an object is null

My-Component:

<template>     <div></div>     <slot></slot>  </template>    <script lang="ts">  import { defineComponent, onMounted } from "vue";    export default defineComponent({      name: "my-component",      props: {          text: {              type: String,              default: '',              required: true,          },      },      setup( _, ctx) {                    onMounted( () => {              if (ctx.slots.default) {                  console.log( (ctx.slots.default()[0]) ); // <- property "el" - is null              }          })        },  });  </script>  
https://stackoverflow.com/questions/67428598/how-to-get-htmlelement-from-child-component-in-slot May 07, 2021 at 11:20AM

没有评论:

发表评论