source

Vuex 내 구성 요소가 상태 변경에 반응하지 않음

goodcode 2022. 8. 28. 09:36
반응형

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];
}

Vue 문서

언급URL : https://stackoverflow.com/questions/56013457/vuex-my-component-doesnt-react-to-state-changes

반응형