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.

Figure 5.19. How the listing model should look To fix this problem, we'll need to transform the model<br />

before we pass it to <strong>Vue</strong>. To save you having to think too much about this, I've put the transformation<br />

function into a file, resources/assets/<strong>js</strong>/helpers.<strong>js</strong>. This file is a JavaScript module that we can import<br />

into our entry file <strong>and</strong> use by simply passing the model object into the function.<br />

resources/assets/<strong>js</strong>/app.<strong>js</strong>: import <strong>Vue</strong> from 'vue'; import {<br />

populateAmenitiesAndPrices } from './helpers'; let model =<br />

JSON.parse(window.vuebnb_listing_model); model =<br />

populateAmenitiesAndPrices(model);<br />

Once we've added this <strong>and</strong> refreshed the page, we should see the new model data<br />

in the text parts of the page (although still with the hard-coded images):

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

Saved successfully!

Ooh no, something went wrong!