user9046370
user9046370

Reputation:

How can I access child component data from a parent in Vue?

I am trying to access data from a single-file component in Vue, but can't find any way of doing it. I have tried using $emit, but can't get thath to work either. The data string has to be blank as it gets modified by an input field.

I have seen others' solutions here on SO, but either the don't fit with my problem or I can't get them to work. I want to try to keep it as simple and understandable as possible.

Upvotes: 6

Views: 9728

Answers (1)

You can use the special attribute ref:

<child-comp ref="child"></child-comp>

In JS:

vm.$refs.child.YOUR_DATA

Hope this helps!

Upvotes: 19

Related Questions