In watch property, what is the difference between calling property using () and not using them?
export default {
watch: {
// syntax with ()
test() {
if (this.test) {
//some work
} else {
//some work
}
},
// syntax without ()
labels: {
immediate: true,
deep: true,
handler(option) {
//some work
}
}
}
}
Futhermore what is the aim of immediate and deep?
watchis lazy by default, meaning it would only run after an initial change to the source has occurred.adding
immediate: trueessentially let's the callback of the watch to run when the component is initialized. In essence, like thedoblock of ado whileloop in certain languages.you can find more and the deep and eager watch at the docs https://vuejs.org/guide/essentials/watchers.html