I've seen some questions about vue.js watchers, but i didnt find a question handling my problem, so here it is:
In my SomeComponent.vue i use this code:
...
props: ['value']
,
watch: {
value(val) {
console.log(val);
}
},
In my parent vue page, that uses this component i use this, which is working:
<template>
<div>
<SomeComponent
v-model="test"
></SomeComponent>
</div>
</template>
data() {
return {
test: {}
};
},
created() {
this.test = this.DoSomething();
},
If i add another property the watcher is not triggered anymore:
<template>
<div>
<SomeComponent
v-model="test"
></SomeComponent>
</div>
</template>
data() {
return {
test: {}
};
},
created() {
this.test.Prop1 = this.DoSomething();
this.test.Prop2 = "Test";
},
EDIT: After Behappy's Answer my Component Part looks like this now:
...
props: ["value"],
watch: {
value: {
handler(val) {
console.log(val);
},
deep: true
}
},