在src/store/index.js
```javascript
import Vuex from 'vuex'
import Vue from 'vue'
Vue.use( Vuex )
// 1. 定义store 模块
const store = new Vuex.Store({
state:{
count: 0
},
actions:
/*
1. actions是一个对象
2. acitons里面放的都是方法
3. 方法的作用是创建动作,发送动作
*/increment ( { commit }, val ) {
// 动作创建
const action = {
type: INCREMENT,
val
}
// 发送动作
commit( action )
}
},
mutations:{
/*
* 也是一个对象
* 里面存放的也是方法
* 方法名称是actions发送来的动作的类型
* 接收两个参数
* state就是数据 , action就是actions发来的动作
* mutations作用是用来修改数据的
* payload表示从组件传递过来的参数 负载
*/
INCREMENT ( state,action ) {
//修改数据
state.count ++
}
},
getters: {}, //getters表示帮助 视图【 组件 】 获得store中的 state
modules // 用来实现数据分块的
})// 2. 导出store模块
export default store
```