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.

Principle #1 – Single source of<br />

truth<br />

Components may have local data that only they need to know about. For<br />

example, the position of the scroll bar in the user list component is probably of<br />

no interest to other components: <strong>Vue</strong>.component('user-list', { data() { scrollPos:<br />

... } });<br />

But any data that is to be shared between components, for example application<br />

data, needs to be kept in a single place, separate from the components that use it.<br />

This location is referred to as the store. Components must read application data<br />

from this location <strong>and</strong> not keep their own copy to prevent conflict or<br />

disagreement:<br />

Figure 8.2. Centralized data simplifies application state

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

Saved successfully!

Ooh no, something went wrong!