Complete Vue.js 2 Web Development_ Practical guide to building end-to-end web development solutions with Vue.js 2

(singke) #1
Large Application Patterns with Vuex Chapter 18

You don't have to explicitly use Vuex in your expression when you are
importing Vuex as an ES6 module. You just need to write
import { mapState } from 'Vuex'.
Then, the mapState function will be available.

The mapState method takes an array of strings as a parameter, looks for a state variable


in the store with the same name as the string, and creates a computed property with the


same name. You can do this with as many variables as you want.


There's more...


If you followed along on a local npm project, open the Vue developer tools (unfortunately
Vue developer tools is not available when using JSFiddle) and you will see that a new


mutation is issued with each message. Consider that you click on the little clock:

Free download pdf