react 修改state为对象中的某一个属性值
2019-01-02 本文已影响0人
JennyGao66
state={
payAmount:0,
coursewareName:'',
orderInfo:{}
}
let data = Object.assign({}, this.state.orderInfo, { payMethod: value })
console.log("data debugger",data)
debugger
this.setState({
orderInfo: data
})
console.log("data",data)
console.log("orderInfo",this.state.orderInfo)
console.log("payMethod",this.state.orderInfo.payMethod)
但是结果

红框里有属性payMethod,绿框的美原油
data debugger中有

data有这个属性,但是
this.state.orderInfo没有这个属性
this.state.orderInfo.payMethod
undefined