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 badges2 Answers
Reset to default 8You 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,
},
}
本文标签:
版权声明:本文标题:javascript - How to handle Uncaught Error: [nuxt] storeindex.js should export a method that returns a Vuex instance - Stack Over 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744268521a2598065.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论