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.

Receiving in the client<br />

With the initial state now ready, let's add it to our HomePage component. Before we<br />

can use it though there's an additional aspect we need to consider: the listing<br />

summaries are grouped by country. Look again at Figure 7.7 to see how these<br />

groups are displayed.<br />

After we've parsed our injected data, let's modify the object so the listings are<br />

grouped by country. We can easily create a function to do this, as every listing<br />

object has an address property in which the country is always explicitly named,<br />

for example, No. 51, Hanzhong Street, Wanhua District, Taipei City, Taiwan 108.<br />

To save you having to write this function, I have supplied one in the helpers<br />

module called groupByCountry which can be imported at the top of the component<br />

configuration.<br />

resources/assets/components/HomePage.vue: ... import { groupByCountry }<br />

from '../<strong>js</strong>/helpers'; let serverData = JSON.parse(window.vuebnb_server_data);<br />

let listing_groups = groupByCountry(serverData.listings); export default { data()<br />

{ return { listing_groups } } } <br />

We'll now see through <strong>Vue</strong> Devtools that HomePage has successfully loaded the<br />

listing summaries, grouped by country <strong>and</strong> ready for display:

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

Saved successfully!

Ooh no, something went wrong!