import Vue from 'vue'
import Vuex from 'vuex'
const store = new Vuex.Store({
state: {
count: 0
},
mutations: {
increment (state) {
state.count++
}
}
})
调用和变更状态
store.commit('increment')
console.log(store.state.count) // -> 1
new Vue({
el: '#app',
store: store,
})
methods: {
increment() {
this.$store.commit('increment')
console.log(this.$store.state.count)
}
}
网友评论