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 7.16. Dev Tools console showing error The reason for this is that the component's first render occurs<br />

before the callback in the next hook is called. This means that the initialization values for the component<br />

data are used in the first render.<br />

resources/assets/components/ListingPage.vue: data() { return { title: null, about: null,<br />

address: null, amenities: [], prices: [], images: [] } },<br />

In the HeaderImage declaration, we bind the first image like this: :imageurl="images[0]".<br />

Since the array is initially empty, this will be an undefined value<br />

<strong>and</strong> results in the unh<strong>and</strong>led error.<br />

The explanation is complex, but the fix is easy: just add a v-if to header-image,<br />

ensuring it won't render until valid data is available.<br />

resources/assets/components/ListingPage.vue:

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

Saved successfully!

Ooh no, something went wrong!