access store outside of component vuejs

别等时光非礼了梦想. 提交于 2020-05-10 03:52:48

问题


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


回答1:


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


来源:https://stackoverflow.com/questions/47571543/access-store-outside-of-component-vuejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!