计算属性中
如果只是像下面这样,Vue2都检测不到值的变化,视图不会更新渲染
this.obj.key = value
this.obj[key] = value
Object.assign(this.obj,value)
this.arr[index] = value
this.arr.push(value)
...
视图会一直是上次的数据,但是内部的数据确实变了
解决思路:相当于重新给对象或数组赋值了
this.obj = {...this.obj,...{key:value}}
this.obj = Object.assign({},this.obj,{key:value})
this.arr = [...this.arr,value]
父子组件之间的传值同理,this.$emit把新的值传给父组件的时候也要使用上面的方式数据才会更新