index.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import { store } from 'quasar/wrappers'
  2. import { InjectionKey } from 'vue'
  3. import {
  4. createStore,
  5. Store as VuexStore,
  6. useStore as vuexUseStore,
  7. } from 'vuex'
  8. // import example from './module-example'
  9. // import { ExampleStateInterface } from './module-example/state';
  10. /*
  11. * If not building with SSR mode, you can
  12. * directly export the Store instantiation;
  13. *
  14. * The function below can be async too; either use
  15. * async/await or return a Promise which resolves
  16. * with the Store instance.
  17. */
  18. export interface StateInterface {
  19. // Define your own store structure, using submodules if needed
  20. // example: ExampleStateInterface;
  21. // Declared as unknown to avoid linting issue. Best to strongly type as per the line above.
  22. example: unknown
  23. }
  24. // provide typings for `this.$store`
  25. declare module '@vue/runtime-core' {
  26. interface ComponentCustomProperties {
  27. $store: VuexStore<StateInterface>
  28. }
  29. }
  30. // provide typings for `useStore` helper
  31. export const storeKey: InjectionKey<VuexStore<StateInterface>> = Symbol('vuex-key')
  32. export default store(function (/* { ssrContext } */) {
  33. const Store = createStore<StateInterface>({
  34. modules: {
  35. // example
  36. },
  37. // enable strict mode (adds overhead!)
  38. // for dev mode and --debug builds only
  39. strict: !!process.env.DEBUGGING
  40. })
  41. return Store;
  42. })
  43. export function useStore() {
  44. return vuexUseStore(storeKey)
  45. }