I have similiar problem to this: VueJs 2.0 - how to listen for `props` changes but in my case, I send object from parent to child, also with passing down few times to use benefits of object references in JS.
There is an example, but working fine:
<div id="app">
<child :myprop="myObj"></child>
<button @click="text = 'Another text'">Change text</button>
</div>
<script>
new Vue({
el: '#app',
data: {
myObj: {
id: null
}
},
components: {
'child' : {
template: `<div>
<p>{{ myprop.id }}</p>
<select v-model="myprop.id">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</div>`,
props: ['myprop'],
watch: {
'myprop.id': function(newVal, oldVal) { // watch it
console.log('Prop changed: ', newVal, ' | was: ', oldVal)
}
}
}
}
});
</script>
https://jsfiddle.net/8hqwg6Ln/
In my case, I set v-model on select to "parentObj.id" and then add watcher for this. The goal is to change other parentObj property after changing id - user select id, after that I search this id in my array and set parentObj.price, which is v-model to other component (modified input) on the same level as select field.
When I change slection, watcher is not triggered. If I add @change with my custom method, it works, but with delay (I see this in vue dev tools, must refresh to get current data), also, it doesn't work for second input component - it doesn't see changes parentObj.price.
What is the best approach to use complex collection with passing down and modify this one collection with many different components? I think, I can add "copies" of properties to local level (so, create data with id and price on child), add watchers, and use this.$set to update received props. But... is it good option, maybe here is something better?