一张图了解vuex的运行机制
2019-04-30 本文已影响0人
我性本傲

vuex独立的提供响应式数据的。
运行机制:单向数据流。
vuex提供数据(state)来驱动视图(vue components),通过dispath派发actions,在其中可以做一些异步的操作,然后通过commit来提交mutations,最后mutations来更改state。
为什么要经过mutations这一层呢?
因为要在插件devtools中记录数据的变化吗,以便调试。
mutations需要一个纯同步的操作。
如果没有异步的操作,可以直接从vue components提交到mutations
核心概念:
1.state 提供一个响应式数据
2.getter 借助vue的计算属性computed来实现缓存
3.mutation 更改state方法
4.action 触发mutation方法
5.module vue.set动态添加state到响应式数据