I'm experiencing problems with vue watchers.
How to explain such behavior: watcher on test.a is triggered on creating test.b property?
vm = new Vue({
data: {
test: { a: {}, c: {} }
}
})
vm.$watch('test.a', () => {console.log('> test.a changed')})
vm.$watch('test.b', () => {console.log('> test.b changed')})
vm.$watch(() => vm.test.c, () => {console.log('> test.c changed')}, {deep: true})
setTimeout(() => {
console.log('creating: test.b')
Vue.set(vm.test, 'b', {})
}, 10)
setTimeout(() => {
console.log('changing: test.b')
vm.test.b = 1
}, 20)
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.11/vue.min.js"></script>
EDIT:
In real world I use deep watchers, but such behavior was observed for both: normal and deep watcher types.
Creating new property triggers all sibbling deep watches and in most cases normal watches.