Upon initialization of a component, the data callback is executed as follows:
data(){
return {
name: myNameGetter(),
age: myAgeGetter(),
// etc...
}
},
Following that, a notification is sent to a parent component regarding logic from this particular component:
created(){
this.$emit('personFullName', this.getFullName());
},
The same logic is then implemented within the watchers as well:
watch: {
person: function(){
this.name = myNameGetter();
this.age = myAgeGetter();
this.$emit('personFullName', this.getFullName());
}
}
Is there a more efficient way to handle this?
The only solution I have thought of so far is:
watch: {
person: function(){
const data = this.data();
for (let key in data) this[key] = data[key];
this.$emit('personFullName', this.getFullName());
}
}
However, it still seems somewhat redundant. How has the community addressed this issue?