
本文共 2443 字,大约阅读时间需要 8 分钟。
vuex���������Vue���������������������������������������������������������������������������������������������������������������������Vuex���������������������������������������������������������������������������������������������������Vuex������������������������������������������������������������������������������������������������������Vuex���������������������������������������������������
Vuex���������vue.use������������������������������install���Store������������������������Vuex���������������������������������������
let Vue;export class Store { constructor(options) {}}export const install = (_Vue) => { Vue = _Vue; applyMixin(Vue);};
Vuex���������������������������mixin������������������vue������������������store���������������������������this.$store���������������������������������
function vuexInit() { const options = this.$options; 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; } // ...}
���������������������������������������������������vue���������������������������������
this._vm = new Vue({ data: { $$state: state, },});
������convenient property������������������������������������������������v������RRRRRRRRRRR ...���������property���������vue������������������������������������vue���������property���API���������������������������vm.���������property���������������
������getter���mutations���actions������������
this.mutations = {};forEachValue(options.mutations, (fn, key) => { this.mutations[key] = (payload) => fn.call(this, this.state, payload);});commit = (type, payload) => { this.mutations[type](payload);};
���������������������vuex������������������������������actions���mutations������������������������������getter���������
���������������mapMutations���������mutation���������������������������������������������
const mapMutations = (mutationList) => { let res = {}; for (let i = 0; i < mutationList.length; i++) { const name = mutationList[i]; res[name] = function(payload) { this.$store.commit(name, payload); }; } return res;};
���������������vuex���������������vue������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
[���������������������]
发表评论
最新留言
关于作者
