## 修改数据(同步操作)
~~~
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
export default new Vuex.Store({
state: {
cont: 0
},
mutations: {
add (state) {
state.cont++
},
addn (state, num: number) {
state.cont += num
}
},
actions: {
},
modules: {
}
})
~~~
####1 修改数据
~~~
this.$store.commit('add')
this.$store.commit('addn',10)
~~~
### 2 修改数据
~~~
import { mapState, mapMutations } from 'vuex'
methods: {
...mapMutations(['jian']),
jianfa () {
this.jian(3)
}
}
~~~