In VueJS, I have seen different ways of accessing parent properties from a component. Say I want to use the parent property items
in my component.
First way
The component has a props value bound to a parent property:
.js
Vue.component("example", {
template: "<div></div>",
props: ["myItems"]
});
.html
<example v-bind:my-items="items"></example>
Second Way
The child component accesses a parent's properties directly, like this:
this.$parent.items
Question
Is there a reason to use the more elaborate first method over the second? Is there an overhead to "duplicating" data like that, vs. accessing it directly when needed?
The
props
should be mutated in the parent component, according to the official doc :So in order to update
props
from child component you should usethis.$emit
event and send the new value in order to handle the update in the parent one.