Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
Couldn't access state in vuex 4

I'm using vuex v4 with composition api. The problem is I couldn't access store states in components but I can see them in vue-devtools. When I wanna access store state it gave me undefined.

store/index.ts:

import { InjectionKey } from "vue";
import {
  createStore,
  createLogger,
  Store,
  useStore as vuexUseStore,
} from "vuex";
import { ConfigStateType } from "./config/state";
import config from "./config";

export enum ModuleTypes {
  CONFIG = "CONFIG",
}

export interface StateInterface {
  config: ConfigStateType;
}

export const key: InjectionKey<Store<StateInterface>> = Symbol();

export const store = createStore<StateInterface>({
  modules: {
    [ModuleTypes.CONFIG]: config,
  },
  strict: debug,
});

export function useStore() {
  return vuexUseStore(key);
}

vue js main.ts:

import { store, key } from "./store";

createApp(App).use(store, key).use(router).mount("#app");

In my component:

import { useStore } from "@/store";

setup() {
    const store = useStore();

   const recaptchaSiteKey = computed(
      () => store.state.config.googlerecaptcha_site_key
    );

return {
recaptchaSiteKey
}
}

always recaptchaSiteKey returns undefined, but in vue-devtools states are filled.

vuex devtool: enter image description here

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!