let Vue; class Store{ constructor(option){ this.options = option; DefineReactive defineReactive Vue.util.defineReactive(this,'state',option.state); This. getters = resolvegetters(this); // Add getters, mutatios action methods to this instance. this.commit = resolveCommit.bind(this); this.dispatch = resolveDispatch.bind(this); } } const resolvegetters = (vm)=>{ let obj = Object.create(null); let keys = Object.keys(vm.options.getters); keys.forEach((value)=>{ obj[value] = vm.options.getters[value].call(vm,vm.state) }) return obj; } function resolveCommit (type, rest){ console.log(this); this.options.mutations[type](this.state, rest); } function resolveDispatch (type, rest){ this.options.actions[type](this, rest); } const install = (_Vue) => {// install Vue = _Vue; Vue. Mixin ({beforeCreate(){if(this.$options.store){this.$store = this.$options.store}else{ this.$store = this.$parent && this.$parent.$store; } } }) } export default { Store, install }Copy the code