[英]Vuex My component doesn't react to state changes
我無法讓我的組件對 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]; }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.