반응형
이.$store.dispatch().then()은 Vuex에서 작동하지 않습니다.
프로젝트에서 VUEX를 사용하고 있는데 상태가 변경된 후 몇 가지 작업을 수행해야 합니다.다음은 스토어 모듈입니다.js:
const state = {
activeEvent: null
};
const mutations = {
SET_ACTIVE_EVENT(state, activeEvent) {
state.activeEvent = activeEvent;
}
};
const actions = {
setActiveEvent({ commit }, activeEvent) {
commit("SET_ACTIVE_EVENT", activeEvent);
}
};
export default {
state,
mutations,
actions
};
코드는 다음과 같습니다.
this.$store.dispatch("setActiveEvent", event).then(() => {
//Something...
});
이렇게 하면 콘솔에서 다음 오류 메시지가 나타납니다.
Uncaught (in promise) TypeError: Cannot read property 'then' of undefined
내가 지금까지 시도한 것:
const actions = {
setActiveEvent({ commit }, activeEvent) {
return new Promise(resolve => {
commit("SET_ACTIVE_EVENT", activeEvent);
resolve(true);
});
}
};
그리고:
const actions = {
setActiveEvent({ commit }, activeEvent) {
return new Promise(resolve => {
resolve(commit("SET_ACTIVE_EVENT", activeEvent));
});
}
};
그러나 둘 다 동일한 오류를 반환합니다.내가 뭘 잘못하고 있지?
편집:
도움이 될 경우 다음을 사용합니다.
- vue ^2.5.16
- vue-timeout ^1.0.6
- vuex ^3.0.1
- vuex-timeout ^1.0.0
언급URL : https://stackoverflow.com/questions/60776648/this-store-dispatch-then-is-not-working-in-vuex
반응형
'programing' 카테고리의 다른 글
Vue.js 2: sass/scss에서 사용할 수 없는 범위 스타일 (0) | 2022.08.25 |
---|---|
각 요소를 슬롯에 랩하려면 어떻게 해야 하나요? (0) | 2022.08.25 |
java.util 인스턴스를 역직렬화할 수 없습니다.START_OBJECT 토큰에서 ArrayList가 벗어났습니다. (0) | 2022.08.25 |
어레이 Vuex의 뮤트 (0) | 2022.08.18 |
다른 문자열 리터럴에 대한 두 문자 포인터의 주소가 동일합니다. (0) | 2022.08.18 |