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.

Image URLs<br />

When we created ImageCarousel, we hard-coded the image URLs. With props, we<br />

now have a mechanism for sending dynamic data from the root instance down to<br />

a component. Let's bind the root instance data property images to a prop, also<br />

called images, in our ImageCarousel declaration.<br />

resources/views/app.blade.php: <br />

Now, delete the data property images in the ImageCarousel component, <strong>and</strong> instead<br />

declare images as a prop.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: <strong>Vue</strong>.component('image-carousel', { props: ['images'],<br />

data() { return { index: 0 } }, ... }<br />

The root instance will now be responsible for the state of the image URLs, <strong>and</strong><br />

the image carousel component will just be responsible for displaying them.<br />

Using <strong>Vue</strong> Devtools, we can inspect the state of the image carousel component,<br />

which now includes images as a prop value instead of a data value:

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

Saved successfully!

Ooh no, something went wrong!