Answer the question
In order to leave comments, you need to log in
How to track the state of two computed properties using logical AND in vue watch?
That is, there is a property A and B, it is necessary for watch to work when both A and B change. If there is no such built-in capability, then how could it be bypassed?
Answer the question
In order to leave comments, you need to log in
In the end, how did. Added 2 state variables and merged 2 properties into one compoundAB:
data () {
return {
stateAChanged: false,
stateBChanged: false
}
},
computed: {
getA () {
....
},
getB () {
....
},
compoundAB() {
return `${this.getA}|${JSON.stringify(this.getB)}`
}
}
watch: {
compoundAB: function (newVal, oldVal) {
const [oldA , oldB ] = oldVal.split('|');
const [newA, newB] = newVal.split('|');
if (oldA !== newA) {
this.stateAChanged = true
}
if (oldB !== newB) {
this.stateBChanged = true
}
if (this.stateAChanged && this.stateBChanged) {
this.stateAChanged = this.stateBChanged = false
}
}
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question