[英]How to receive $emitted data from child to parent?
From the child component, I am emitting an event fetchtab
, along with some data
just like that:从子组件中,我发出一个事件
fetchtab
,以及一些类似的data
:
this.$emit('fetchtab', data);
I want that data
to be assigned to a currentData
prop of my parent component (the root component).我希望将该
data
分配给我的父组件(根组件)的currentData
道具。
data: {
currentData: {}
}
This data
is an array of objects.该
data
是一个对象数组。 I need to iterate over that array in my parent component:我需要在我的父组件中迭代该数组:
<ul>
<li v-for="item in currentData">@{{ item.name }}</li>
</ul>
But I can't figure out how do I fill in the currentData
in the first place.但我不知道如何首先填写
currentData
。 I know I could use a) @fetchtab="myMethod"
or, b) this.$on('fetchtab', fn)
我知道我可以使用 a)
@fetchtab="myMethod"
或 b) this.$on('fetchtab', fn)
But where and how do I use it?但是我在哪里以及如何使用它?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.