Problem Statement
How do you write watchers for nested data and trigger them initially?
Explanation
Use the object syntax with options: { deep: true } to traverse nested properties (be mindful of performance), and { immediate: true } to run the callback right after the watcher is registered.
Code Solution
SolutionRead Only
watch: {
settings: {
deep: true,
immediate: true,
handler(val){ console.log('settings changed', val) }
}
}Practice Sets
This question appears in the following practice sets: