programing

vuex: 네임슬레이드모듈 내에서 콜 변환이 필요한 이유는 무엇입니까?

coolbiz 2022. 11. 3. 23:00
반응형

vuex: 네임슬레이드모듈 내에서 콜 변환이 필요한 이유는 무엇입니까?

다음과 같은 vuex 구성을 가지고 있습니다.

import listing from '@/store/modules/listing'
var store = new Vuex.Store({
    modules:
    {
        listing: listing,

    },

리스트 모듈코드는 다음과 같습니다.

import Vue from 'vue'
const listing = {
    namespaced: true,
    state: {
        listingAllItems: [],
        listingSelectedItems: [],       
    },
    mutations: {
        updateListingAllItems(state, param) {
        },
    },
    actions: {
        getListingItems(context, param) {
            var tempThis = this;
            return new Promise((resolve, reject) => {
                var url = 'http://WS/';
                Vue.http.get(url).then(response => {
                    tempThis.commit('updateListingAllItems', response.data);
                }).catch(error => reject(error));
            })
        },
    },
    getters: {}
}

export default listing

.commit ('updateListingAllItems', response.data)호출하면 알 수 없는 변환 유형 updateListingAllItems가 나타납니다.

Vuex 가이드에 따르면

이름 지정 게터 및 액션에는 현지화된 게터, 디스패치 및 커밋이 포함됩니다.즉, 같은 모듈에 프레픽스를 입력하지 않고 모듈애셋을 사용할 수 있습니다.

그러면 오류 메시지가 표시되는 이유는 무엇입니까?

액션 메서드 내부this가게입니다.코드가 스토어 인스턴스에서 프리픽스되지 않은 변환을 커밋합니다.

바꾸면

tempThis.commit('updateListingAllItems', response.data);

로.

context.commit('updateListingAllItems', response.data);

기대했던 걸 얻을 수 있을 거야

언급URL : https://stackoverflow.com/questions/46738473/vuex-why-calling-mutation-from-within-a-namespaced-module-requires-a-prefix

반응형