Bas Broens
Bas Broens

Reputation: 81

get list of element with slot attribute vue

i have in my parent a custom tag <datatable> with slot references in it:

 <datatable> 
        <div slot="week"> 5</div>
        <div slot="day"> monday</div>
    </datatable>

Is it possible to get an array of the slot names?

tried: document.querySelectorAll('[slot]');

But all i get is an empty nodelist.

Upvotes: 0

Views: 431

Answers (1)

IVO GELOV
IVO GELOV

Reputation: 14289

You can get the array like this (https://v2.vuejs.org/v2/api/#vm-slots):

 <datatable ref="comp"> 
        <div slot="week"> 5</div>
        <div slot="day"> monday</div>
    </datatable>
console.log(Object.keys(this.$refs.comp.$slots));

Upvotes: 1

Related Questions