javascript - Can the raact setState() method only modify some properties of an object?
给我你的怀抱
给我你的怀抱 2017-05-19 10:33:56
0
1
488
this.state.style:{
width:
height:
color
}
//修改属性
this.setState({style:{}})

Now I want to add an attribute to it through setState. Can I only add one attribute and keep the other attributes with their original values?

给我你的怀抱
给我你的怀抱

reply all(1)
漂亮男人

When using Object.assign(), be careful not to return the original object, but a new object:

this.setState(Object.assign({}, this.state.style, {width: 666}))
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template