State and mutator methods
Let's add two new state properties to our Vuex store: listings and listing_summaries. These will be arrays that store our listings and listing summaries respectively. When the page first loads, or when the route changes and the API is called, the loaded data will be put into these arrays rather than being assigned directly to the page components. The page components will instead retrieve this data from the store.
We'll also add a mutator method, addData, for populating these arrays. It will accept a payload object with two properties: route and data. route is the name of the route, for example, listing, home, and so on. data is the listing or listing summary data retrieved from the document head or the API.
resources/assets/js/store.js ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access