Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to pass elements to a vue component?

when I need to pass some information between child and parent element I use props. But is there a way to pass elements to the component, for example like this

<MyComponent>
 <router-link to="/oneOfTheList">OneOfTheList</router-link>
</MyComponent>

Router-Link seems to do it somehow…
How can I specify where the elements will be placed in my component

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

This is called slot

ComponentA.vue

<div>
  <slot></slot>
</div>

ComponentB.vue

<component-a>
    <span>test</span> // this part will be shown inside component A's slot tags
</component-a>

Here you go

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading