使用Object.assign()
,要注意不要返回原对象,应该返回一个新对象:
1、state 定义 state = { OAInfo: {app_name: '', user_id: '', app_login_id: ''}, } 2、触发的修改方法: thisOAval(event) { let data = Object.assign({}, this.state.OAInfo, { app_login_id: event.target.value }) this.setState({ OAInfo: data }) }
在redux中 修改store对象中同理,对已记录state属性进行 filter 循环查询,并替换对应元素后,整体赋值state对象。
*注意:并不推荐使用此方法。因为redux只是记录数据状态,进行store修改操作,应该在state中操作比较规范; redux只进行数据记录,逻辑判断与修改放在模块state中,action则只进行异步请求处理
case SELECTROLEPUSH: return state.set('selectedRoles', state.get('selectedRoles').filter(item => (item.role_id !== action.payload.role_id)).push(action.payload)) // 添加
return state.set('selectedRoles', state.get('selectedRoles').filter(item => (item.role_id === action.payload))) // 修改
return state.set('defInputVal', { ...state.get('defInputVal'), func_ids: action.payload })