npm install vuex@next --save
- state: Shared data itself
- getters: Read gateway of state
- actions: Asynchronous changing data
- mutations: Synchronous changing data
- modules: Fractally Scaled out group of states
import { createApp } from 'vue'
import { createStore } from 'vuex'
const store = createStore({
state () {
return {
count: 0
}
},
mutations: {
increment (state) {
state.count++
}
}
})
const app = createApp({ })
app.use(store)
store.commit('increment')
console.log(store.state.count)
methods: {
increment() {
this.$store.commit('increment')
console.log(this.$store.state.count)
}
}