I'm currently utilizing Vuex for Vue 2 which is similar to Redux for React. Recently, I came across a helpful example that demonstrates updating a counter. Here is the code snippet:
import Vuex from 'vuex'
import Vue from 'vue'
Vue.use(Vuex)
var store = new Vuex.Store({
state: {
counter: 0
},
mutations: {
INCREMENT (state) {
state.counter ++
}
}
})
export default store
This led me to wonder, what sets this approach apart from simply creating a manual store without Vuex? In that case, it would look like this:
import Vue from 'vue'
var store = {
state: {
counter: 0
},
mutations: {
INCREMENT (state) {
state.counter ++
}
}
}
export default store