将初始化Vue根组件时传入的store设置到this对象的store属性,层层嵌套进行设置。在任意组件中执行 this.$store 都能找到装载的那个store对象,vuexInit方法实现如下:
将初始化vue根组件时传入的store设置到this对象的$store属性上
Vuex init hook,injected into each instances init hooks list.
function vuexInit(){ var options = this.options; //store injection if(options.store){ this.store = typeof options.store === 'function' ?options.store() :options.store; } else if (options.parent && options.parent.store){ this.store = options.parent.$store; } }
root(this.store=parent.store=parent.store=parent.$store)