반응형
동적으로 등록된 모듈에서 vuex 변환에 액세스할 수 없음
vue 컴포넌트에 대해 API 데이터를 가져와 유지하는 모듈을 만들었습니다.
import Vue from 'vue';
export default {
namespaced: true,
state() {
return {
all: []
}
},
getters: {
all(state) {
return state.all;
}
},
mutations: {
all(state, data) {
Vue.set(state, 'all', data);
},
clear(state) {
Vue.set(state, 'all', []);
}
},
actions: {
async init({ commit, state }) {
let response = await this.axios.get('/api/v1/teams/', {
params: {
includes: 'users'
}
});
if (response.status === 200) {
let data = response.data.data.filter(function (element) {
return element.users.length > 0;
});
commit('userTeamSelect/all', data, {root: true});
} else {
Vue.toasted.error('Could not fetch team data', {
duration: 10000
});
}
}
}
}
생성 시 모듈을 동적으로 등록하고 삭제하기 전에 저장소에서 모듈을 삭제하는 컴포넌트가 있습니다.
created() {
if (this.$store.getters['userTeamSelect/all'] === undefined) {
this.$store.registerModule('userTeamSelect', UserTeamSelectModule);
this.$store.dispatch('userTeamSelect/init');
}
},
beforeDestroy() {
if (this.$store.getters['userTeamSelect/all'] !== undefined) {
this.$store.commit('userTeamSelect/clear');
this.$store.unregisterModule('userTeamSelect');
}
},
이 컴포넌트가 사용되고 있는 페이지로 이동하면 콘솔에 다음 오류 메시지가 나타납니다.[vuex] unknown mutation type: userTeamSelect/all
이 변환은 다이내믹모듈의 init 액션 내에서만 호출되므로 어딘가에 문제가 있을 수 있습니다.둘 다 로컬로 전화하려고 했어요.commit('all', data)
글로벌하게commit('userTeamSelect/all', data, {root:true})
운도 없이
문제없이 액션을 호출할 수 있기 때문에 모듈이 vuex 스토어에 추가되었을 것입니다.돌연변이가 등록되지 않은 것 같아요?정상적으로 동작하거나 알 수 없는 액션에 대한 오류를 수신할 수 있습니다.
누가 저를 올바른 방향으로 안내해주실 수 있나요?
언급URL : https://stackoverflow.com/questions/60563917/cannot-access-vuex-mutation-in-dynamically-registered-module
반응형
'programing' 카테고리의 다른 글
#ifdefinside #dispossible (0) | 2022.06.02 |
---|---|
C의 시리얼 포트에서 열기, 읽기 및 쓰기는 어떻게 합니까? (0) | 2022.06.02 |
fs.readdir는 기다릴 수 있지만 이유는 알 수 없습니다. (0) | 2022.06.02 |
vuex 작업에서 bootstrap-vue 모달 및 토스트를 호출하는 방법은 무엇입니까? (0) | 2022.06.02 |
Vue 컴포넌트 외부에 있는 VueRouter에 액세스합니다. (0) | 2022.06.02 |