所以我有以下代码:
case LOGIN_SUCCESS:
return Object.assign({}, state, {
message: "Login successful",
cause: null,
username: action.username,
fullname: action.fullname,
credit: action.credit,
id: action.id,
topmenutype: action.topmenutype,
authenticated: true
});
case LOCATION_SUCCESS:
return Object.assign({}, state, {
location: action.location
});
所以基本上我想发生的是将location
添加到上面的对象中。有可能吗?
答案 0 :(得分:0)
您可以执行类似上面的操作。
return Object.assign({}, {
...state,
location: action.location
});
答案 1 :(得分:0)
您无需使用Object.assign
并创建对象的深层副本。相反,您可以使用传播运算符。您可以详细了解两者Here
case LOGIN_SUCCESS:
return {
...state,
message: "Login successful",
cause: null,
username: action.username,
fullname: action.fullname,
credit: action.credit,
id: action.id,
topmenutype: action.topmenutype,
authenticated: true
};
case LOCATION_SUCCESS:
return {
...state,
location: action.location
};