admin管理员组

文章数量:1400591

I have setup a default store in Nuxt in store/index.js as the documentation remends. When I try to render my app I'm getting the following error:

Uncaught Error: [nuxt] store/index.js should export a method that returns a Vuex instance.

My store/index.js file looks like this:

import Vuex from 'vuex'
import Vue from 'vue'
import myModule from './myModule'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: () => ({

  }),
  mutations: {},
  actions: {},
  modules: {
    myModule: myModule
  }
})
export default store

How do I handle this?

I have setup a default store in Nuxt in store/index.js as the documentation remends. When I try to render my app I'm getting the following error:

Uncaught Error: [nuxt] store/index.js should export a method that returns a Vuex instance.

My store/index.js file looks like this:

import Vuex from 'vuex'
import Vue from 'vue'
import myModule from './myModule'

Vue.use(Vuex)

const store = new Vuex.Store({
  state: () => ({

  }),
  mutations: {},
  actions: {},
  modules: {
    myModule: myModule
  }
})
export default store

How do I handle this?

Share Improve this question asked Aug 17, 2021 at 15:54 marcusemarcuse 4,0095 gold badges36 silver badges52 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

You are exporting the Vuex store as a constant, you should export a default method that returns the Vuex store instance.

Your store/index.js file should look like this:

import Vuex from 'vuex'
import Vue from 'vue'
import myModule from './myModule'

Vue.use(Vuex)

export default () => new Vuex.Store({
  state: () => ({

  }),
  mutations: {},
  actions: {},
  modules: {
    myModule: myModule
  }
})

I do have the following and it's working great.

import { test } from './modules/tasty_module'

const state = () => ({})
const mutations = {}
const actions = {}
const getters = {}

export default {
  state,
  mutations,
  getters,
  actions,
  modules: {
    testModule: test,
  },
}

本文标签: