Vue JS Watching deep nested object

前端 未结 4 1944
深忆病人
深忆病人 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:16

    You could use the 'watch' method.. for example if your data is:

    data: {
        block: {
            checkbox: {
                active:false
            },
            someotherprop: {
                changeme: 0
            }
        }
    }
    

    You could do something like this:

    data: {...},
    watch: {
       'block.checkbox.active': function() {
            // checkbox active state has changed
            this.block.someotherprop.changeme = 5;
        } 
    }
    

提交回复
热议问题