We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
手写Vuex核心原理
let Vue //myVuex.js class Store{ constructor(options) { this.vm = new Vue({ data:{ state:options.state } }) let getters = options.getter || {} this.getters = {} Object.keys(getters).forEach(getterName=>{ Object.defineProperty(this.getters,getterName,{ get:()=>{ return getters[getterName](this.state) } }) }) let mutations = options.mutations || {} this.mutations = {} Object.keys(mutations).forEach(mutationName=>{ this.mutations[mutationName] = (arg)=> { mutations[mutationName](this.state,arg) } }) let actions = options.actions this.actions = {} Object.keys(actions).forEach(actionName=>{ this.actions[actionName] = (arg)=>{ actions[actionName](this,arg) } }) } dispatch(method,arg){ this.actions[method](arg) } commit=(method,arg)=>{ console.log(method); console.log(this.mutations); this.mutations[method](arg) } get state(){ return this.vm.state } } let install = function(vue){ Vue = vue Vue.mixin({ beforeCreate(){ if (this.$options && this.$options.store){ this.$store = this.$options.store }else { this.$store = this.$parent && this.$parent.$store } } }) } let Vuex = { Store, install } export default Vuex
The text was updated successfully, but these errors were encountered:
No branches or pull requests
手写Vuex核心原理
The text was updated successfully, but these errors were encountered: