IT이야기

검색되지 않은 오류 처리 방법: [nuxt] store/index.js는 Vuex 인스턴스를 반환하는 방법을 내보내야 함

cyworld 2022. 4. 17. 15:51
반응형

검색되지 않은 오류 처리 방법: [nuxt] store/index.js는 Vuex 인스턴스를 반환하는 방법을 내보내야 함

Nuxt에 기본 저장소를 설정한 경우store/index.js설명서의 권장 사항에 따름.앱을 렌더링하려고 하면 다음 오류가 표시됨:

검색되지 않은 오류: [nuxt] store/index.js는 Vuex 인스턴스를 반환하는 메서드를 내보내야 한다.

나의store/index.js파일 모양:

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

어떻게 해야 하지?

Vuex 저장소를 상수로 내보내는 경우 Vuex 저장소 인스턴스를 반환하는 기본 방법을 내보내십시오.

당신의store/index.js파일은 다음과 같아야 한다:

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

나는 다음과 같은 것들을 가지고 있고 그것은 훌륭하게 작동하고 있다.

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

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

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

참조URL: https://stackoverflow.com/questions/68820509/how-to-handle-uncaught-error-nuxt-store-index-js-should-export-a-method-that

반응형