How can I access child component data from a paren

2020-03-27 11:18发布

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.

标签: vue.js
1条回答
一夜七次
2楼-- · 2020-03-27 12:00

You can use the special attribute ref:

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

In JS:

vm.$refs.child.YOUR_DATA

Hope this helps!

查看更多
登录 后发表回答