capiono
capiono

Reputation: 2997

access store outside of component vuejs

I have a file for configuring my OpenID Connect authentication

export const authMgr = new Oidc.UserManager({
  userStore: new Oidc.WebStorageStateStore(),
  authority: **appsetting.oidc**
})

I want to access my state in order to get the value of appsetting.

I did this:

import store from './store'

const appsetting = () => store.getters.appsetting

but my appsetting is always returning undefined

what I my missing?

Store:

app.js

const state = {
  appsetting: appsetting,
}

export {
  state 
}

getters.js

const appsetting = state => state.appsetting

export {
  appsetting
}

index.js

export default new Vuex.Store({
  actions,
  getters,
  modules: {
    app
  },
  strict: debug,
  plugins: [createLogger]
})

when I print the value of store.getters, it returns this:

{
  return __WEBPACK_IMPORTED_MODULE_2__store__["a" /* default */].getters;
}

No the actual store objects

Upvotes: 41

Views: 41193

Answers (2)

Ave
Ave

Reputation: 33

As for 2023 accesing store with

import {store} from '../store/index'
store.getters.appSettings

wasnt working for me but after removing curly brackets like so:

import store from '../store/index'
store.getters.appSettings

It started working as intended

Upvotes: 1

Shay Altman
Shay Altman

Reputation: 2760

Try to import 'store' with curly brackets

import {store} from '../store/index'

store.getters.appSettings

Another option is to access from the vue property

import Vue from 'vue'

Vue.store.getters.appSettings

Upvotes: 82

Related Questions