반응형
Vuex/Vues의 작업에서 다른 작업을 호출하는 방법
나는 호출까지 이들을 삭제하신 후 사이트의 목록을 업데이트하려고 하고 있어요.getSites()
아래와 같은 방법
코드
import http from 'services/http.service';
import logging from 'services/logging.service';
const sites = http('sites', localStorage);
export default {
getSites({dispatch}) {
console.log('getSites')
sites.all().then((response) => {
dispatch('setSites', response.data.results);
});
},
deleteSite({dispatch}, site) {
return sites.delete(site).then(() => {
this.getSites() // <-------- doesn't works
});
},
};
다음과 같은 오류가 발생함
삭제 실패 ReferenceError: getSite가 정의되지 않음
질문.
새 항목 목록 가져오기를 호출하려면 어떻게 해야 하는가?또는 구성 요소 내에서 수행할 것인가?then()
?
actions.js에서 호출을 제거하고 구성 요소 내에서 호출을 수행했다.
import actions from 'vuex/actions';
export default{
// …
methods: {
// …
delete_site(site){
return this.deleteSite(site).then(response => {
this.getSites(); // <----------- call from here
});
},
vuex: {
actions: {
getSites: actions.getSites,
deleteSite: actions.deleteSite,
}
}
}
참조URL: https://stackoverflow.com/questions/38980267/how-to-call-another-action-from-actions-in-vuex-vues
반응형
'IT이야기' 카테고리의 다른 글
최대 절전 모드 프록시를 실제 엔티티 개체로 변환하는 방법 (0) | 2022.05.18 |
---|---|
C의 주 인수에 대한 인수 (0) | 2022.05.17 |
어떻게 비동기적으로 Vuetify 텍스트 필드를 확인하기 위해? (0) | 2022.05.17 |
Vuex mapState 경로와 경로 매개 변수에 근거한다. (0) | 2022.05.17 |
경고:수 을 왼쪽 시프트 형식의 탭 너비입니다. (0) | 2022.05.17 |