25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Distinguishing carousel controls<br />

The CarouselControl component should have two possible states: either leftpointing<br />

or right-pointing. When clicked by the user, the former will ascend<br />

through the available images, the latter will descend.<br />

This state should not be internally determined, but instead passed down from<br />

ImageCarousel. To do so, let's add a prop dir to CarouselControl that will take a string<br />

value, <strong>and</strong> should be either left or right.<br />

With the dir prop, we can now bind the correct icon to the i element. This is<br />

done with a computed property which appends the prop's value to the string fachevron-,<br />

resulting in either fa-chevron-left or fa-chevron-right.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: <strong>Vue</strong>.component('image-carousel', { template: ` <br />

`, ... components: { 'carousel-control': { template: ``, props: [ 'dir' ], computed: { classes() { return 'carouselcontrol<br />

fa fa-2x fa-chevron-' + this.dir; } }<br />

} } }<br />

Now we can see the carousel control icons correctly directed:

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

Saved successfully!

Ooh no, something went wrong!