简单理解vuex原理
发布日期:2021-05-10 22:09:21 浏览次数:10 分类:精选文章

本文共 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������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������

[���������������������]

上一篇:对UI库的一些感触
下一篇:vue mixins原理

发表评论

最新留言

不错!
[***.144.177.141]2025年04月15日 17时47分46秒