let Vue;

class Sstore {
  constructor(options) {
    this.mutations = options.mutations;
    this.actions = options.actions;
    this._getters = options.getters;
    this.getters = {};
    const computed = {};
    const that = this;
    Object.keys(this._getters).forEach((key) = > {
      const fn = that._getters[key];
      computed[key] = function() {
        return fn(that.state);
      };
      Object.defineProperty(that.getters, key, {
        get() {
          returnthat._vm[key]; }}); });// Change $$state to the responsetime method, another method: vue.util.definereactive
    this._vm = new Vue({
      data: {
        $$state: options.state,
      },
      computed,
    });
  }
  get state() {
    return this._vm._data.$$state;
  }
  commit(type, payload) {
    this.mutations[type](this.state, payload);
  }
  dispatch(type, payload) {
    this.actions[type](this, payload); }}function install(_vue) {
  Vue = _vue;
  // Mixin can delay the execution of code, Vue. Use (router) before new Vue, fixed at this time $options has no value
  Vue.mixin({
    beforeCreate() {
      if (this.$options.store) {
        Vue.prototype.$store = this.$options.store; }}}); }export default {
  Store: Sstore,
  install: install,
};

Copy the code