Vue JS Watching deep nested object

前端 未结 4 1936
深忆病人
深忆病人 2021-02-04 23:47

Disclaimer: This is my first attempt at building an MVVM app I have also not worked with vue.js before, so it could well be that my issue is a result of a more

4条回答
  •  醉梦人生
    2021-02-05 00:22

    If you want to watch the object as a whole with all its properties, and not only just one property, you can do this instead:

     data() {
        return {
           object: {
              prop1: "a",
              prop2: "b",
           }    
        }
     },
     watch: {
        object: {
            handler(newVal, oldVal) {
                // do something with the object
            },
            deep: true,
        },
    },
    

    notice handler and deep: true

提交回复
热议问题