25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Slots<br />

We've learned so far that the content of a component is defined by its own<br />

template, not by its parent, so we wouldn't expect the following to work: Parent content <br />

But it will work if MyComponent has a slot. Slots are distribution outlets inside a<br />

component, defined with the special slot element: <strong>Vue</strong>.component('mycomponent',<br />

{ template: `<br />

<br />

<br />

Child content<br />

` });<br />

new <strong>Vue</strong>({ el: '#app' });<br />

This renders as:<br />

<br />

<br />

Parent content<br />

Child content<br />

<br />

<br />

If ComponentB has a slot in its template, like this:<br />

<strong>Vue</strong>.component('component-b', {<br />

template: ''<br />

});<br />

We can solve the problem just stated without having to use a cumbersome v-for:<br />

<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!