Vue - Deep watching an array of objects and calculating the change?

前端 未结 5 1349
北荒
北荒 2020-11-28 03:10

I have an array called people that contains objects as follows:

Before

[
  {id: 0, name: \'Bob\', age: 27},
  {id: 1, n         


        
5条回答
  •  孤街浪徒
    2020-11-28 03:43

    It is well defined behaviour. You cannot get the old value for a mutated object. That's because both the newVal and oldVal refer to the same object. Vue will not keep an old copy of an object that you mutated.

    Had you replaced the object with another one, Vue would have provided you with correct references.

    Read the Note section in the docs. (vm.$watch)

    More on this here and here.

提交回复
热议问题