VueJS: watching two properties VueJS: watching two properties vue.js vue.js

VueJS: watching two properties


Watch a computed value.

computed:{    combined(){        return this.a && this.b    }}watch:{    combined(value){        if (value)            //do something    }}

There is a sort of short hand for the above using $watch.

vm.$watch(  function () {    return this.a + this.b  },  function (newVal, oldVal) {    // do something  })


It's pretty much the same solution as @Bert suggested. But you can just do the following:

data() {  return {      combined: {          a: false,           b: false,       }  }},

Then:

watch: {    combined:{        deep:true,        handler    }}