0👍
✅
As you can see, the default export of the file is a function that creates a new store, therefore import store from './store'
is a function, not the real store object. I’ve come to a solution — export the store
object separately.
let Store;
export default store(function (/* { ssrContext } */) {
Store = createStore<StateInterface>({
modules: {
// example
sidebar_state,
authentication,
crud,
view,
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: !!process.env.DEBUGGING,
});
return Store;
});
export function getStore() {
return Store;
}
Now store is available this way:
import { getStore } from './store';
let user = await getStore().dispatch('authentication/getUser');
** There is another way (here), but accessing SSR Context is not possible in creating the store.
const Store = new Vuex.Store({...})
export { Store }
export default function (/* ssrContext */) {
return Store
}
import { Store } from './store';
let user = await Store.dispatch('authentication/getUser');
Source:stackexchange.com