使用Vuex
在组件中使用state
通过this.$store.state访问state
使用计算属性来响应state的变化
使用getters
通过this.$store.getters访问getters
可以传递参数给getters
提交mutation
通过this.$store.commit方法触发mutation
传递一个包含type属性的payload对象
分发action
通过this.$store.dispatch方法触发action
可以处理异步操作
模块化Vuex
将store分割成不同的模块
每个模块有自己的state、mutations、actions、getters
在根store中注册模块
使用namespaced选项来隔离命名空间