Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 971
capiono Avatar asked Nov 30 '17 10:11

capiono


People also ask

How do I access Vuex store outside component?

js? To access a Vuex store outside of a component in Vue. js, we can import the store and use it directly.

How do you access child components at Vue?

To access child component's data from parent with Vue. js, we can assign a ref to the child component. And then we can access the child component data as a property of the ref. to assign the markdown ref to the markdown component.

Is Vuex store reactive?

Vuex stores are reactive. When Vue components retrieve state from it, they will reactively and efficiently update if the store's state changes. You cannot directly mutate the store's state. The only way to change a store's state is by explicitly committing mutations.


1 Answers

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 
like image 107
Shay Altman Avatar answered Oct 06 '22 07:10

Shay Altman