vuex错误, should export a method which returns a Vuex instance.

store/index.js should export a method which returns a Vuex instance.

采用的模块化写法就这样报错,现在换回普通模式就对了
框架是nuxt.js
不知道哪写错了,求大神,不是很懂ES6

这是代码结构

clipboard.png

按照上图顺序,这分别是对应代码

export const getActiveIndex = state => {
    return state.activeIndex || 1;
};
import mutations from '../../mutation/body/index.js';
import * as getters from '../../getter/body/index.js';

const body = {
    state: mutations.state,
    mutations: mutations.mutations,
    getters: getters
}

export default body
import * as types from '../../mutation-types/body/index.js';

const state = {
    activeIndex: 1,
};

const mutations = {
    [types.SIDEMENU] (state,{activeIndex}) {
        state.activeIndex = activeIndex
    }
}

export default {
  state,
  mutations
};
export const SIDEMENU = 'SIDEMENU'
import Vue from 'vue';
import Vuex from 'vuex';

import body from './module/body/index.js';

Vue.use(Vuex);
const debug = process.env.NODE_ENV !== 'production';

export default new Vuex.Store({
    modules: {
        body,
    },
strict: false
});

这是错误提示

Nuxt.js Error:

Error: [nuxt] store/index.js should export a method which returns a Vuex instance.
    at getModule (.nuxt/store.js:53:10)
    at Object.module.exports.Object.defineProperty.value (.nuxt/store.js:16:14)
    at __webpack_require__ (webpack:/webpack/bootstrap c85da9788740a1862fce:25:0)
    at Object.<anonymous> (server-bundle.js:1028:68)
    at __webpack_require__ (webpack:/webpack/bootstrap c85da9788740a1862fce:25:0)
    at Object.<anonymous> (server-bundle.js:1461:65)
    at __webpack_require__ (webpack:/webpack/bootstrap c85da9788740a1862fce:25:0)
    at server-bundle.js:95:18
    at Object.<anonymous> (server-bundle.js:98:10)
    at evaluateModule (D:\work\inner-eye\node_modules\vue-server-renderer\build.js:5820:21)
    at D:\work\inner-eye\node_modules\vue-server-renderer\build.js:5878:18
    at Promise (<anonymous>)
    at D:\work\inner-eye\node_modules\vue-server-renderer\build.js:5870:14
    at Nuxt.renderToString (D:\work\inner-eye\node_modules\vue-server-renderer\build.js:6022:9)
    at P (D:\work\inner-eye\node_modules\pify\index.js:49:6)
    at Promise (<anonymous>)
阅读 8.5k
4 个回答

图片描述

嗯。。。你返回个函数就好了。。。

已解决,我看了下是写法变了,返回的需要时函数,而不是实例了

import Vue from 'vue';
import Vuex from 'vuex';

import body from './module/body/index.js';

Vue.use(Vuex);
const debug = process.env.NODE_ENV !== 'production';

export default () => {
    return new Vuex.Store({
                modules: {
                    body,
                },
            strict: false
            });
}

报错信息出在这里吗
clipboard.png

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题