Vue.js 从nuxtjs中的js文件外部访问存储

Vue.js 从nuxtjs中的js文件外部访问存储,vue.js,vuex,nuxt.js,Vue.js,Vuex,Nuxt.js,我正在尝试从组件外部的文件访问存储 当我搜索这个问题时,我看到有人说我应该从我的文件中导入存储,然后我可以访问它,但我无法实现这一点 我的商店是这样建造的: const createStore = () => { return new Vuex.Store({ state: { ... }, getters: { ... }, mutations: { ... }, actions: { ... }, }) } 我试着把它导入我的js文件,就像我看

我正在尝试从组件外部的文件访问存储 当我搜索这个问题时,我看到有人说我应该从我的文件中导入存储,然后我可以访问它,但我无法实现这一点

我的商店是这样建造的:

const createStore = () => {
  return new Vuex.Store({
    state: { ... },
    getters: { ... },
    mutations: { ... },
    actions: { ... },
  })
}
我试着把它导入我的js文件,就像我看到的一样

import store from '@/store'

有什么想法吗?

您可以通过在实例化时注册来导入存储,如下所示:

外部文件
some service.js

export default class SomeService {
  constructor(store) {
    this.store = store
  }
  doStuff() {
    this.store.dispatch('someAction')
  }
}

你能说明类是如何实例化的吗?
存储源于哪里?