This commit is contained in:
rca 2024-07-19 00:08:15 +09:00
parent e2250443a8
commit 4b91ab3024
2 changed files with 19 additions and 55 deletions

View File

@ -1,7 +1,8 @@
import { GetterTree } from 'vuex';
import { RootStateInterface } from '../index';
import { AccountStateInterface } from './state';
const getters: GetterTree<AccountStateInterface, any> = {
const getters: GetterTree<AccountStateInterface, RootStateInterface> = {
getToken(state: AccountStateInterface): string {
return state.token;
},

View File

@ -1,59 +1,22 @@
import { store } from 'quasar/wrappers';
import {
createStore,
Module,
createComposable,
Getters,
Mutations,
} from 'vuex-smart-module';
import { createStore } from 'vuex'
import accountStateModule from './account';
import { AccountStateInterface } from './account/state';
class RootState {
count = 1;
}
class RootGetters extends Getters<RootState> {
get count () {
return this.state.count;
}
multiply (multiplier: number) {
return this.state.count * multiplier;
}
}
class RootMutations extends Mutations<RootState> {
add (payload: number) {
this.state.count += payload;
}
}
// This is the config of the root module
// You can define a root state/getters/mutations/actions here
// Or do everything in separate modules
const rootConfig = {
state: RootState,
getters: RootGetters,
mutations: RootMutations,
modules: {
//
},
};
export const root = new Module(rootConfig);
export default store(function (/* { ssrContext } */) {
const rootStore = createStore(root, {
strict: !!process.env.DEBUGGING,
// plugins: []
// and other options, normally passed to Vuex `createStore`
});
return rootStore;
});
export const useStore = createComposable(root);
export interface RootStateInterface {
// Define your own store structure, using submodules if needed
account: AccountStateInterface;
}
export default function (/* { ssrContext } */) {
const Store = createStore({
modules: {
accountStateModule
},
// enable strict mode (adds overhead!)
// for dev mode and --debug builds only
strict: process.env.DEBUGGING === 'true'
})
return Store
}