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

查看:979
本文介绍了vue.js - 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

这是代码结构

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

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>)

解决方案

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

这篇关于vue.js - vuex错误, should export a method which returns a Vuex instance.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆