Watch props change on vuejs
based on that code, it should work, so the issue may be somewhere else. Can you post more code?
if you want to run immediately, you can use immediate
. This is the syntax:
watch: {
searchStore: {
immediate: true,
deep: true,
handler(newValue, oldValue) {
}
}
},
The deep: true
setting will deep-watch for a change within the object.
When you are updating parts of this object in the parent component, make sure you use Vue's $set
function.
this.$set(this.searchStore, 'myKey', {price: 12.22});
further reading: https://v2.vuejs.org/v2/guide/reactivity.html#Change-Detection-Caveats