Illustration:
export default {
data() {
return {
value1: 1,
value2: 2
}
},
mounted() {
this.value1 = 2
console.log(this.value2)
},
watch: {
value1: {
handler(newValue1) {
this.value2 = newValue1 * 3
}
}
}
}
Anticipated outcome: the browser displays number 6 in the console
Current result: the browser displays number 2 in the console
In this scenario, I attempted to update the value of 'value2' after changing the value of 'value1', but it shows the original 'value2' instead of the modified one. Is there a method to immediately execute the watcher handler after triggering? I understand that for this example, computed properties can be utilized, however, I have specific data requirements in my project.
I made an effort to set the immediate property of the watcher to true, however, it did not work as expected.