March 2018
Beginner to intermediate
344 pages
7h 7m
English
We can now commit actions and have these actions return a new version of the state. The next step is to create getters so that we can return sliced parts of our state across our application. Let's create a new file inside src/store named getters.js and add the following:
export default { count(state) { return state.count; },};
As we have a minuscule example, the use of a getter for this property isn't entirely necessary, but as we scale our application(s), we'll need to use getters to filter state. Think of these as computed properties for values in the state, so if we wanted to return a modified version of this property for the view-layer, we could as follows:
export default { count(state) { return state.count > 3 ? 'Above three!' ...Read now
Unlock full access