-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating

Learning Vue.js 2
By :

The Vuex store contains essentially two things: state and mutations. State is an object that represents the initial state of the application data. Mutations is also an object containing action functions that affect the state. Vuex store is just a plain JavaScript file that exports these two objects and tells Vue to use Vuex (Vue.use(Vuex)
). Then it can be imported into any other component. If you import it in the main App.vue
file and register the store on the Vue
application initialization, it is passed to the whole children chain and can be accessed through the this.$store
variable. So, very roughly, in a very simplified way, we would create a store, import it in the main app, and use it in a component in the following way:
//CREATE STORE
//initialize state
const state = {
msg: 'Hello!'
}
//initialize mutations
const mutations = {
changeMessage(state, msg) {
state.msg = msg...