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.

Feature lists<br />

Let's continue our process of refactoring <strong>Vue</strong>bnb into components, <strong>and</strong> abstract<br />

the amenities <strong>and</strong> prices lists. These lists have a similar purpose <strong>and</strong> structure, so<br />

it makes sense that we create a single, versatile component for both.<br />

Let's remind ourselves of how the markup for the lists currently looks.<br />

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

Amenities <br />

@{{ amenity.title }} <br />

<br />

Prices @{{ price.title }}: @{{ price.value }}<br />

<br />

The main difference between the two lists is inside the ...<br />

section, as the data being displayed in each list has a slightly different<br />

structure. The amenities have an icon <strong>and</strong> a title whereas the prices have a title<br />

<strong>and</strong> a value. We'll use a slot in this section to allow the parent to customize the<br />

content for each.<br />

But first, let's create the new FeatureList component file: $ touch<br />

resources/assets/components/FeatureList.vue<br />

We'll move the markup for one of the lists in, using a slot to replace the list<br />

content. We'll also add a prop for the title <strong>and</strong> move in any list-related CSS.<br />

resources/assets/components/FeatureList.vue: {{ title }} <br />

export default { props: ['title'] } hr { border: 0; border-top: 1px<br />

solid #dce0e0; } .list { display: flex; flex-wrap: nowrap; margin: 2em 0; }

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

Saved successfully!

Ooh no, something went wrong!