查看参考地址: https://vuex.vuejs.org/zh/
vuex 状态管理模式,相当于数据的中间商
注意: === 为相同
属性有:
1.State === vue中的data —> 存放数据
2.Getter === vue中的计算属性computed —>将已有的数据进行计算再次利用
3.Mutation === vue中的方法集methods —> 创建函数调用
4.Action === vue中的监听器watch —> 时刻关注 data 中 数值的变化
5.Module === 相当于开启了另一个分支,每个模块拥有自己的 state、mutation、action、getter、甚至是嵌套子模块——从上至下进行同样方式的分割:
const moduleA = {state: () => ({ ... }),mutations: { ... },actions: { ... },getters: { ... }
}const moduleB = {state: () => ({ ... }),mutations: { ... },actions: { ... }
}const store = new Vuex.Store({modules: {a: moduleA,b: moduleB}
})store.state.a // -> moduleA 的状态
store.state.b // -> moduleB 的状态