mrcrowl / vuex-typex

Typescript builder for strongly-typed access to Vuex Store modules
MIT License
193 stars 22 forks source link

JS ERROR TypeError: undefined is not an object (evaluating '_this._store.rootGetters') #25

Open VannaDii opened 5 years ago

VannaDii commented 5 years ago

Calling metrics.getMetricsDesc(); which is defined as:

import Vue from 'vue';
import Vuex, { Store } from 'vuex';
import { getStoreBuilder } from 'vuex-typex';
import { MetricsState } from './metricsState';

export interface RootState {
  metrics: MetricsState
}

Vue.use(Vuex);
const store: Store<RootState> = getStoreBuilder<RootState>().vuexStore();
export { store };
export default store;
import { RootState } from './store';
import { getStoreBuilder } from 'vuex-typex';

const initialMetricsState: MetricsState = {
    allMetrics: [],
    isLoading: false
}
const builder = getStoreBuilder<RootState>().module('metrics', initialMetricsState);
const metricsDesc = builder.read(state => state.allMetrics.sort((a, b) => (a.date > b.date ? -1 : 1)), 'metricsDesc');
const metrics = {
    // State
    get state() { return builder.state(); },

    // Getter as method
    getMetricsDesc() {
        return metricsDesc();
    },
}
zhangxinghao commented 4 years ago

@GioCirque I ran into the same error, did you ever find out why you got this error?