반응형
Vuex 내 구성 요소가 상태 변경에 반응하지 않음
기존 요소를 수정할 때만 Vuex 스토어 변경에 대응하도록 구성 요소를 설정할 수 없습니다.컴포넌트가 네스트 되어 있는 방법이나 그 무엇과도 전혀 관계가 없는 것으로 알고 있습니다.디버깅을 몇 시간이나 하고 나서, 모든 것을 시도하면, 스토어의 변화를 상세하게 관찰할 수 있는 것이 전부입니다.
currentVisit.pathologies ex: {id:1, title:"Something"}에 요소를 추가하면 정상적으로 동작하지만 요소를 편집해도 컴포넌트가 스토어 업데이트에 응답하지 않음
UPDATED
addPathology: (state, payload) => {
state.currentVisit.pathologies.push(payload);
},
updatePathology: (state, payload) => {
//this is the "reduced" code, this is how I found my component doesn't react.
state.currentVisit.pathologies[0] = payload;
}
state{
currentVisit: {
id: "5",
tumors: null,
pathologies: [],
examinations: null,
allergies: null,
diagnoses: null,
comorbidities: null,
chemotherapies: null,
radiations: null,
immunotherapies: null,
operations: null
}
}
createPathology: ({ commit, getters }, payload) => {
return new Promise((resolve, reject) => {
//do axios
//then commit updatePathologies
//then return promise response
baseAxios
.post("visits/" + getters.visitId + "/pathologies", payload)
.then(res => {
commit("addPathology", res.data.data);
resolve(res);
})
.catch(e => {
reject(e);
});
});
}
editPathology: ({ commit, getters }, payload) => {
return new Promise((resolve, reject) => {
baseAxios
.patch(
"visits/" + getters.visitId + "/pathologies/" + payload.id,
payload
)
.then(res => {
//commit("updatePathology", res.data.data);
resolve(res);
})
.catch(e => {
reject(e);
});
});
}
를 변경하다updatePathology반응도에 대한 돌연변이:
updatePathology: (state, payload) => {
const pathologies = state.currentVisit.pathologies;
pathologies[0] = payload;
// assign a new array reference for reactivity
state.currentVisit.pathologies = [...pathologies];
}
언급URL : https://stackoverflow.com/questions/56013457/vuex-my-component-doesnt-react-to-state-changes
반응형
'source' 카테고리의 다른 글
| C++와 Java의 "일반" 유형의 차이점은 무엇입니까? (0) | 2022.08.28 |
|---|---|
| Java: sun.security.provider.certpath.SunCertPathBuilder예외: 요청된 대상에 대한 올바른 인증 경로를 찾을 수 없습니다. (0) | 2022.08.28 |
| 앵커 태그가 있는 VueJ @click (0) | 2022.08.28 |
| Java에서 long 초기화 (0) | 2022.08.28 |
| Java 문자열에서 공백 제거 (0) | 2022.08.28 |