programing

Nuxt.js 스토어, 다른 스토어에 디스패치액션

prostudy 2022. 7. 2. 11:02
반응형

Nuxt.js 스토어, 다른 스토어에 디스패치액션

내 Nuxt.js 앱에 2개의 스토어가 있는데 다른 스토어에 액션을 디스패치해야 합니다.

export const actions = {
   addToCart({ state, commit, dispatch }) {
    dispatch('CartLoadingStore/enableLoadingBar')

    this.$axios
      .post('something')
      .then(response => {
        (...)
        dispatch('CartLoadingStore/disableLoadingBar')
      })
  },
}

다른 가게로 액션을 보낼 수 없을 것 같습니다.그래요?아니면 그렇게 하는 방법이 있나요?

위의 경우 다음 오류가 발생합니다.

[vuex] unknown local action type: CartLoadingStore/enableLoadingBar, global type: StoreTheActionDispatchedFrom/CartLoadingStore/enableLoadingBar

디스패치 콜에 루트 파라미터를 추가해야 합니다.

dispatch('CartLoadingStore/disableLoadingBar', null, { root: true })

여기 문서

언급URL : https://stackoverflow.com/questions/54280875/nuxt-js-store-dispatch-action-to-other-store

반응형