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

前端 未结 5 1309
北荒
北荒 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:49

    This is what I use to deep watch an object. My requirement was watching the child fields of the object.

    new Vue({
        el: "#myElement",
        data:{
            entity: {
                properties: []
            }
        },
        watch:{
            'entity.properties': {
                handler: function (after, before) {
                    // Changes detected.    
                },
                deep: true
            }
        }
    });
    

提交回复
热议问题