Can you take a look at this simple example?
export default {
data() {
return {
name: "Amy",
age: 18,
};
},
computed: {
combinedDataForWatching() {
return {
name: this.name,
age: this.age,
};
},
},
watch: {
combinedDataForWatching() {
console.log("Triggered!");
},
},
mounted() {
setTimeout(() => {
this.name = "Bob";
this.age = 20;
}, 1000);
},
};
The message "Triggered!"
will only be logged once, can you explain why?
What is the mechanism behind Vue's batch update detection?