Vue 2.x源码(六)Vuex实现
Vuex的install实现
通过
applyMixin(Vue)
在Vue的beforeCreate
时注入为了回去同一份store,会尝试从
options.store
(root节点)和options.parent.$store
获取store
双向绑定实现
修改state
在严格模式中:会调用store._vm.$watch(...)
,监听state的改动,如果!_committing
则会抛出错误。
只能使用mutation更改state
action
action是异步的,使用的是Promise。 - -没啥好说的。
Vuex和Vue的冲突
见官网:Vuex表单处理
当在严格模式中使用 Vuex 时(修改state),在属于 Vuex 的 state 上使用 v-model 会比较棘手:
由于v-model修改是在Vue中修改的,但是在Vuex的store._vm.$watch(...)
所监听中,this._committing
并不是_committing
Last updated