这是我在减速器中的初始状态
const initialState = {
ids:[],
periodData: {}
}
我想将 periodID: 3477dac1-d14a-4aef-b544-d8945b2442b9 的备注从“test”更新为“test1”
这是我要更新的操作:
export function updatePeriod(data){
return function(dispatch){
let formData = new FormData();
formData.append("periodID", data.periodID);
formData.append("periodName", data.periodName);
formData.append("startDate", fecha.format(data.startDate, 'YYYY-MM-DD'));
formData.append("endDate", fecha.format(data.endDate, 'YYYY-MM-DD'));
formData.append("remark", data.remark);
formData.append("isActive", 1);
dispatch({type: PERIOD_FETCHING}); //Loading Indicator Appeared
axios.post(`${ROOT_URL}/api/setup/createPeriod`,formData,
{
headers:{authorization:`Bearer `+localStorage.getItem('laravel_user_token')}
}
).then(response => {
let result = {
"periodID": data.periodID,
"periodName": data.periodName,
"startDate": fecha.format(data.startDate, 'YYYY-MM-DD'),
"endDate": fecha.format(data.endDate, 'YYYY-MM-DD'),
"remark": data.remark,
"isActive": '1'
}
console.log(normalize(result, schema.periodSchema));
dispatch({type: PERIOD_UPDATE,
payload: normalize(result, schema.periodSchema)
});
dispatch({type: PERIOD_FETCHED}) //Loading Indicator Disappeared
}).catch((e)=>{
console.log(e)
dispatch({type: PERIOD_FETCH_ERROR,
});
});
}
}
这是结果
console.log(normalize(result, schema.periodSchema));
我仍然对我的减速器如何更新(PERIOD_UPDATE)我商店中的 ids 和 periodData 感到困惑。