【发布时间】:2021-02-19 20:57:05
【问题描述】:
我正在使用带有 Redux 的 Angular 2+ 并且很好, 但不能用新值修改数量
错误是: TypeError:无法分配给对象“[object Object]”的只读属性“数量”
export interface CartState {
readonly cars: CartCarModel[]
}
export class CartCarModel {
constructor (
public carId: string,
public carModel: string,
public quantity: number,
public price: number) { }
}
const initialState: CartState = {
cars: []
}
function reducerFunc (state: CartState, id: string, quantity: number) {
const nextState = produce(state, draft => {
draft.cars.find(d => d.carId === id).quantity = quantity
})
return Object.assign({}, state, {
drinks: nextState
})
}
【问题讨论】:
标签: javascript object redux immer.js redux-reducers