Home > Net >  Is there a way to pass elements to a vue component?
Is there a way to pass elements to a vue component?

Time:03-02

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

CodePudding user response:

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

  • Related