Использование vuex-машинописного текста и получение inital состояния неопределенно все время. Как только я сброшу состояние, он работает, но только при перезагрузке и обновлении окна. Вот моя настройка для некоторого простого модуля:
import Vue from "vue";
import Vuex from "vuex";
import { module } from "./some_module";
let store = new Vuex.Store({
modules: {
module,
},
plugins: [persist({
namespace: "mainnamespace",
initialState: {
},
expires: 7 * 24 * 60 * 60 * 1e3 // 1 week
})
]
});
some_module.ts
export interface State {
something: any;
}
const state: State = {
something: [],
};
export const module = {
namespaced: true,
getters: {
getSomethingArray: (state: State) => {
return state.something;
},
},
mutations: {
resetState: (s: State) => {
const initial = state;
Object.keys(initial).forEach(key => { s[key] = initial[key]; });
},
}
actions: {///}
}
const { commit, read, dispatch } =
getStoreAccessors<HistoryState, any>("somemodule");
const mutations = module.mutations;
const getters = module.getters;
const actions = module.actions;
export const getSomeStuffFromHere = read(getters.getSomethingArray);
когда я запускаю приложение и console.log(getSomethingArray(this.$store))
я получил undefined
и когда я console.log(this.$store)
я могу видеть somemodule nemespace
но его состояние не something: []
а some __ob__: Observer
Это проводное исправлено с добавлением состояния:
export const module = {
namespaced: true,
state: state,
getters: {
getSomethingArray: (state: State) => {
return state.something;
},
},
mutations: {
resetState: (s: State) => {
const initial = state;
Object.keys(initial).forEach(key => { s[key] = initial[key]; });
},
}
actions: {///}
}