对于复杂的数据类型,比如说数组或者对象,
在Vue之中可以使用:
data() {
return {
obj: dataObject
}
}
method: {
modify: function(newObj) {
this.obj = newObj
}
}
但是react就要使用:
this.setState({
obj: Object.asign({}, oldObj, newObj)
})
Vue可以直接修改对象的引用,但是react不能够直接修改,而是要使用Object.asign的方式,请问底层的原因是什么?为什么这样呢?
react分Component和PureComponent Component不用assign也可以 PureComponent不行 因为在shouldComponentUpdate做了浅比较 vue用了getter setter react没有