ForeveHG / Frontend-Daily-Interview

学习,尝试回答一些前端面试题
1 stars 0 forks source link

56. vue中vm.$set() 为什么能解决对象新增属性不能响应的问题 #58

Open ForeveHG opened 4 years ago

ForeveHG commented 4 years ago

使用Object.definedPrototype实现的响应式对象,新属性没有getter、setter方法,添加这个新属性时也不会触发属性的setter,所以直接添加新属性是不能响应的,vm.$set会将新添加的属性变成响应式的,再手动触发依赖通知