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.

Saved state<br />

The ListingSave component does not have any local data; we will instead keep any<br />

saved listings in our <strong>Vue</strong>x store. To do this, we will create an array in the store<br />

called saved. Each time the user toggles the saved state of a listing its ID will be<br />

either added or removed from this array.<br />

To begin, let's add a state property to our <strong>Vue</strong>x store. This object will hold any<br />

data we want to be globally available to the components of our app. We will add<br />

the saved property to this object <strong>and</strong> assign it an empty array.<br />

resources/assets/<strong>js</strong>/store.<strong>js</strong>: ...<br />

export default new <strong>Vue</strong>x.Store({ state: { saved: [] } });

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

Saved successfully!

Ooh no, something went wrong!