6

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.

3
  • 3
    Share some code please :) Commented Feb 23, 2018 at 18:32
  • As a general rule, you should not reach into other components for their data. Show what you tried with $emit. Commented Feb 23, 2018 at 18:45
  • This answer might help you :) stackoverflow.com/questions/48877688/… Commented Feb 23, 2018 at 19:12

1 Answer 1

19

You can use the special attribute ref:

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

In JS:

vm.$refs.child.YOUR_DATA

Hope this helps!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.